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 = Hash.new @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.kind_of?(Symbol) raise ArgumentError, "You must use a symbol when defining a new resource!" end @name = resource_name if prototype_params unless prototype_params.kind_of?(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 60 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 64 def to_s "#{name}" end