Reputation: 10122
I have a chef recipe name my_recipe
and I would like to add a library to it to assist me in getting some stuff done, while still being able to run chefspec smoothly.
I read the extend recipe documentation, but couldn't find how to extends (or dynamically create) a class within the recipe namespace.
here is a snippet:
# my_cookbook/recipes/my_recipe.rb
foo = MyRecipe::MyClass.foo
# my_cookbook/libraries/my_class.rb
class Chef
class Recipe
class MyRecipe
unless defined?(Chef::Recipe::MyRecipe::MyClass)
class MyClass
def self.foo
# do stuff
end
end
end
end
end
end
what am I missing?
how chef translate a dsl recipe name my_recipe
to a recipe object (MyRecipe
)?
Upvotes: 0
Views: 316
Reputation: 54249
There is no such translation. I don't really understand where you got this whole class structure for. What you want is just:
module MyHelpers
def self.foo
And then MyHelpers.foo
in your recipe.
Upvotes: 0