Module: Chef::DSL::Definitions Private

Included in:
Recipe
Defined in:
lib/chef/dsl/definitions.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Module containing a method for each declared definition

Depends on declare_resource(name, created_at, &block)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_definition(dsl_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
16
17
# File 'lib/chef/dsl/definitions.rb', line 11

def self.add_definition(dsl_name)
  module_eval <<-EOM, __FILE__, __LINE__ + 1
    def #{dsl_name}(*args, &block)
      evaluate_resource_definition(#{dsl_name.inspect}, *args, &block)
    end
  EOM
end

Instance Method Details

#evaluate_resource_definition(definition_name, *args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Processes the arguments and block as a resource definition.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/chef/dsl/definitions.rb', line 27

def evaluate_resource_definition(definition_name, *args, &block)
  # This dupes the high level object, but we still need to dup the params
  new_def = run_context.definitions[definition_name].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)
end

#has_resource_definition?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


20
21
22
# File 'lib/chef/dsl/definitions.rb', line 20

def has_resource_definition?(name)
  run_context.definitions.key?(name)
end