Class: Chef::ResourceBuilder
- Inherits:
-
Object
- Object
- Chef::ResourceBuilder
- Defined in:
- lib/chef/resource_builder.rb
Instance Attribute Summary collapse
-
#cookbook_name ⇒ Object
readonly
Returns the value of attribute cookbook_name.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#enclosing_provider ⇒ Object
readonly
Returns the value of attribute enclosing_provider.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#recipe_name ⇒ Object
readonly
Returns the value of attribute recipe_name.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#run_context ⇒ Object
readonly
Returns the value of attribute run_context.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #build(&block) ⇒ Object
-
#initialize(type: nil, name: nil, created_at: nil, params: nil, run_context: nil, cookbook_name: nil, recipe_name: nil, enclosing_provider: nil) ⇒ ResourceBuilder
constructor
FIXME (ruby-2.1 syntax): most of these are mandatory.
Constructor Details
#initialize(type: nil, name: nil, created_at: nil, params: nil, run_context: nil, cookbook_name: nil, recipe_name: nil, enclosing_provider: nil) ⇒ ResourceBuilder
FIXME (ruby-2.1 syntax): most of these are mandatory
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/chef/resource_builder.rb', line 34 def initialize(type: nil, name: nil, created_at: nil, params: nil, run_context: nil, cookbook_name: nil, recipe_name: nil, enclosing_provider: nil) @type = type @name = name @created_at = created_at @params = params @run_context = run_context @cookbook_name = cookbook_name @recipe_name = recipe_name @enclosing_provider = enclosing_provider end |
Instance Attribute Details
#cookbook_name ⇒ Object (readonly)
Returns the value of attribute cookbook_name.
28 29 30 |
# File 'lib/chef/resource_builder.rb', line 28 def cookbook_name @cookbook_name end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
25 26 27 |
# File 'lib/chef/resource_builder.rb', line 25 def created_at @created_at end |
#enclosing_provider ⇒ Object (readonly)
Returns the value of attribute enclosing_provider.
30 31 32 |
# File 'lib/chef/resource_builder.rb', line 30 def enclosing_provider @enclosing_provider end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/chef/resource_builder.rb', line 24 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
26 27 28 |
# File 'lib/chef/resource_builder.rb', line 26 def params @params end |
#recipe_name ⇒ Object (readonly)
Returns the value of attribute recipe_name.
29 30 31 |
# File 'lib/chef/resource_builder.rb', line 29 def recipe_name @recipe_name end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
31 32 33 |
# File 'lib/chef/resource_builder.rb', line 31 def resource @resource end |
#run_context ⇒ Object (readonly)
Returns the value of attribute run_context.
27 28 29 |
# File 'lib/chef/resource_builder.rb', line 27 def run_context @run_context end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
23 24 25 |
# File 'lib/chef/resource_builder.rb', line 23 def type @type end |
Instance Method Details
#build(&block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/chef/resource_builder.rb', line 45 def build(&block) @resource = resource_class.new(name, run_context) if resource.resource_name.nil? raise Chef::Exceptions::InvalidResourceSpecification, "#{resource}.resource_name is `nil`! Did you forget to put `provides :blah` or `resource_name :blah` in your resource class?" end resource.source_line = created_at resource.declared_type = type resource.cookbook_name = cookbook_name resource.recipe_name = recipe_name # Determine whether this resource is being created in the context of an enclosing Provider resource.enclosing_provider = enclosing_provider # XXX: this is required for definition params inside of the scope of a # subresource to work correctly. resource.params = params # Evaluate resource attribute DSL if block_given? resource.resource_initializing = true begin resource.instance_eval(&block) ensure resource.resource_initializing = false end end # Run optional resource hook resource.after_created resource end |