Class: Lightchef::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/lightchef/recipe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Recipe

Returns a new instance of Recipe.



9
10
11
# File 'lib/lightchef/recipe.rb', line 9

def initialize(path)
  @path = path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, name = nil, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lightchef/recipe.rb', line 23

def method_missing(method, name = nil, &block)
  cls = Resources.get_resource_class(method)
  resource = cls.new(self, name, &block)
  Logger.info ">>> Executing #{resource.class.name} (#{resource.options})..."
  begin
    resource.run
  rescue Resources::CommandExecutionError
    Logger.error "<<< Failed."
    exit 2
  else
    Logger.info "<<< Succeeded."
  end
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



6
7
8
# File 'lib/lightchef/recipe.rb', line 6

def backend
  @backend
end

#current_runnerObject (readonly)

Returns the value of attribute current_runner.



7
8
9
# File 'lib/lightchef/recipe.rb', line 7

def current_runner
  @current_runner
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/lightchef/recipe.rb', line 5

def path
  @path
end

Instance Method Details

#nodeObject



19
20
21
# File 'lib/lightchef/recipe.rb', line 19

def node
  @current_runner.node
end

#run(runner) ⇒ Object



13
14
15
16
17
# File 'lib/lightchef/recipe.rb', line 13

def run(runner)
  @current_runner = runner
  instance_eval(File.read(@path), @path, 1)
  @current_runner = nil
end