Module: Chef::Mixin::RecipeDefinitionDSLCore
- Includes:
- ConvertToClassName, Language
- Defined in:
- lib/chef/mixin/recipe_definition_dsl_core.rb
Instance Method Summary collapse
Methods included from Language
#platform?, #value_for_platform
Methods included from 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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chef/mixin/recipe_definition_dsl_core.rb', line 36 def method_missing(method_symbol, *args, &block) # Otherwise, we're rocking the regular resource call route. method_name = method_symbol.to_s rname = convert_to_class_name(method_name) super unless Chef::Resource.const_defined?(rname) raise ArgumentError, "You must supply a name when declaring a #{method_name} resource" unless args.size > 0 # If we have a resource like this one, we want to steal its state args << run_context resource = Chef::Resource.const_get(rname).new(*args) resource.load_prior_resource resource.cookbook_name = cookbook_name resource.recipe_name = @recipe_name resource.params = @params resource.source_line = caller[0] # Determine whether this resource is being created in the context of an enclosing Provider resource.enclosing_provider = self.is_a?(Chef::Provider) ? self : nil resource.instance_eval(&block) if block run_context.resource_collection.insert(resource) resource end |