class Chef::ResourceDefinition

Attributes

name[RW]
node[RW]
params[RW]
recipe[RW]

Public Class Methods

new(node = nil) click to toggle source
# File lib/chef/resource_definition.rb, line 30
def initialize(node = nil)
  @name = nil
  @params = {}
  @recipe = nil
  @node = node
end

Public Instance Methods

define(resource_name, prototype_params = nil, &block) click to toggle source
# File lib/chef/resource_definition.rb, line 37
def define(resource_name, prototype_params = nil, &block)
  unless resource_name.is_a?(Symbol)
    raise ArgumentError, "You must use a symbol when defining a new resource!"
  end

  @name = resource_name
  if prototype_params
    unless prototype_params.is_a?(Hash)
      raise ArgumentError, "You must pass a hash as the prototype parameters for a definition."
    end

    @params = prototype_params
  end
  if Kernel.block_given?
    @recipe = block
  else
    raise ArgumentError, "You must pass a block to a definition."
  end
  Chef::DSL::Definitions.add_definition(name)
  true
end
method_missing(symbol, *args) click to toggle source

When we do the resource definition, we’re really just setting new values for the parameters we prototyped at the top. This method missing is as simple as it gets.

# File lib/chef/resource_definition.rb, line 62
def method_missing(symbol, *args)
  @params[symbol] = args.length == 1 ? args[0] : args
end
to_s() click to toggle source
# File lib/chef/resource_definition.rb, line 66
def to_s
  (name).to_s
end