Module: Chef::DSL::Recipe
- Includes:
- Mixin::ConvertToClassName
- Included in:
- Provider, Provider::Deploy, Provider::LWRPBase, Recipe
- Defined in:
- lib/chef/dsl/recipe.rb
Overview
Chef::DSL::Recipe
Provides the primary recipe DSL functionality for defining Chef resource objects via method calls.
Instance Method Summary collapse
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *args, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chef/dsl/recipe.rb', line 34 def method_missing(method_symbol, *args, &block) # If we have a definition that matches, we want to use that instead. This should # let you do some really crazy over-riding of "native" types, if you really want # to. if run_context.definitions.has_key?(method_symbol) # This dupes the high level object, but we still need to dup the params new_def = run_context.definitions[method_symbol].dup new_def.params = new_def.params.dup new_def.node = run_context.node # This sets up the parameter overrides new_def.instance_eval(&block) if block new_recipe = Chef::Recipe.new(cookbook_name, @recipe_name, run_context) new_recipe.params = new_def.params new_recipe.params[:name] = args[0] new_recipe.instance_eval(&new_def.recipe) else # Otherwise, we're rocking the regular resource call route. # Checks the new platform => short_name => resource mapping initially # then fall back to the older approach (Chef::Resource.const_get) for # backward compatibility resource_class = Chef::Resource.resource_for_node(method_symbol, run_context.node) super unless resource_class raise ArgumentError, "You must supply a name when declaring a #{method_symbol} resource" unless args.size > 0 # If we have a resource like this one, we want to steal its state args << run_context resource = resource_class.new(*args) resource.source_line = caller[0] resource.load_prior_resource resource.cookbook_name = cookbook_name resource.recipe_name = @recipe_name resource.params = @params # Determine whether this resource is being created in the context of an enclosing Provider resource.enclosing_provider = self.is_a?(Chef::Provider) ? self : nil # Evaluate resource attribute DSL resource.instance_eval(&block) if block # Run optional resource hook resource.after_created run_context.resource_collection.insert(resource) resource end end |