Class: Bocuse::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/bocuse/unit.rb

Overview

A configuration unit.

Instance Method Summary collapse

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

#bocuseObject

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