Class: Lightchef::Recipe
- Inherits:
-
Object
- Object
- Lightchef::Recipe
- Defined in:
- lib/lightchef/recipe.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#current_runner ⇒ Object
readonly
Returns the value of attribute current_runner.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ Recipe
constructor
A new instance of Recipe.
- #method_missing(method, name = nil, &block) ⇒ Object
- #node ⇒ Object
- #run(runner) ⇒ Object
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.})..." begin resource.run rescue Resources::CommandExecutionError Logger.error "<<< Failed." exit 2 else Logger.info "<<< Succeeded." end end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
6 7 8 |
# File 'lib/lightchef/recipe.rb', line 6 def backend @backend end |
#current_runner ⇒ Object (readonly)
Returns the value of attribute current_runner.
7 8 9 |
# File 'lib/lightchef/recipe.rb', line 7 def current_runner @current_runner end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/lightchef/recipe.rb', line 5 def path @path end |
Instance Method Details
#node ⇒ Object
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 |