Class: Chef::ResourceDefinition
- Inherits:
-
Object
- Object
- Chef::ResourceDefinition
- Includes:
- Mixin::FromFile, Mixin::ParamsValidate
- Defined in:
- lib/chef/resource_definition.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#node ⇒ Object
Returns the value of attribute node.
-
#params ⇒ Object
Returns the value of attribute params.
-
#recipe ⇒ Object
Returns the value of attribute recipe.
Instance Method Summary collapse
- #define(resource_name, prototype_params = nil, &block) ⇒ Object
-
#initialize(node = nil) ⇒ ResourceDefinition
constructor
A new instance of ResourceDefinition.
-
#method_missing(symbol, *args) ⇒ Object
When we do the resource definition, we’re really just setting new values for the paramaters we prototyped at the top.
- #to_s ⇒ Object
Methods included from Mixin::ParamsValidate
Methods included from Mixin::FromFile
Constructor Details
#initialize(node = nil) ⇒ ResourceDefinition
Returns a new instance of ResourceDefinition.
30 31 32 33 34 35 |
# File 'lib/chef/resource_definition.rb', line 30 def initialize(node=nil) @name = nil @params = Hash.new @recipe = nil @node = node end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
When we do the resource definition, we’re really just setting new values for the paramaters we prototyped at the top. This method missing is as simple as it gets.
59 60 61 |
# File 'lib/chef/resource_definition.rb', line 59 def method_missing(symbol, *args) @params[symbol] = args.length == 1 ? args[0] : args end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
28 29 30 |
# File 'lib/chef/resource_definition.rb', line 28 def name @name end |
#node ⇒ Object
Returns the value of attribute node.
28 29 30 |
# File 'lib/chef/resource_definition.rb', line 28 def node @node end |
#params ⇒ Object
Returns the value of attribute params.
28 29 30 |
# File 'lib/chef/resource_definition.rb', line 28 def params @params end |
#recipe ⇒ Object
Returns the value of attribute recipe.
28 29 30 |
# File 'lib/chef/resource_definition.rb', line 28 def recipe @recipe end |
Instance Method Details
#define(resource_name, prototype_params = nil, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 true end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/chef/resource_definition.rb', line 63 def to_s "#{name.to_s}" end |