Class: Bocuse::Unit
- Inherits:
-
Object
- Object
- Bocuse::Unit
- Defined in:
- lib/bocuse/unit.rb
Overview
A configuration unit.
Instance Method Summary collapse
-
#bocuse ⇒ Object
Exposes some of bocuses internal variables to the node that is currently compiled.
- #call(configuration, context) ⇒ Object
-
#cook(recipe, &block) ⇒ Object
Cook adds to the toplevel recipes of this file’s configuration.
-
#helper_module(mod) ⇒ Object
Make the given module a helper module for this node.
-
#include_template(identifier) ⇒ Object
Include the given template name.
-
#initialize(block, project) ⇒ Unit
constructor
A new instance of Unit.
Constructor Details
#initialize(block, project) ⇒ Unit
Returns a new instance of Unit.
5 6 7 8 |
# File 'lib/bocuse/unit.rb', line 5 def initialize(block, project) @block = block @project = project end |
Instance Method Details
#bocuse ⇒ Object
Exposes some of bocuses internal variables to the node that is currently compiled. This allows using node name (, etc…) for formulating clever node configurations.
48 49 50 |
# File 'lib/bocuse/unit.rb', line 48 def bocuse @context.bocuse end |
#call(configuration, context) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bocuse/unit.rb', line 10 def call(configuration, context) @configuration = configuration @context = context # Fill in the config hash argument if the block cares at all. instance_exec(configuration, &@block) ensure @configuration = nil @context = nil end |
#cook(recipe, &block) ⇒ Object
Cook adds to the toplevel recipes of this file’s configuration.
23 24 25 26 |
# File 'lib/bocuse/unit.rb', line 23 def cook recipe, &block @configuration.recipes << recipe @configuration.public_send(recipe, &block) end |
#helper_module(mod) ⇒ Object
Make the given module a helper module for this node.
30 31 32 |
# File 'lib/bocuse/unit.rb', line 30 def helper_module(mod) extend mod end |
#include_template(identifier) ⇒ Object
Include the given template name.
Note: This could be pushed to the configuration.
38 39 40 41 42 |
# File 'lib/bocuse/unit.rb', line 38 def include_template identifier template_block = @project.lookup_template identifier template_block.call(@configuration, @context) end |