Class: Producer::Core::Recipe
- Inherits:
-
Object
- Object
- Producer::Core::Recipe
- Defined in:
- lib/producer/core/recipe.rb,
lib/producer/core/recipe/file_evaluator.rb
Defined Under Namespace
Classes: FileEvaluator
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Class Method Summary collapse
Instance Method Summary collapse
- #compose_macro(name, macro, *base_args) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(env) ⇒ Recipe
constructor
A new instance of Recipe.
- #macro(name, &block) ⇒ Object
- #set(key, value) ⇒ Object
- #source(filepath) ⇒ Object
- #target(hostname = nil) ⇒ Object
- #task(name, *args, &block) ⇒ Object
- #test_macro(name, &block) ⇒ Object
Constructor Details
#initialize(env) ⇒ Recipe
Returns a new instance of Recipe.
24 25 26 27 |
# File 'lib/producer/core/recipe.rb', line 24 def initialize(env) @env = env @tasks = [] end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
22 23 24 |
# File 'lib/producer/core/recipe.rb', line 22 def env @env end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
22 23 24 |
# File 'lib/producer/core/recipe.rb', line 22 def tasks @tasks end |
Class Method Details
.compose_macro(name, macro, *base_args) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/producer/core/recipe.rb', line 13 def compose_macro(name, macro, *base_args) [self, Task].each do |klass| klass.class_eval do define_method(name) { |*args| send macro, *(base_args + args) } end end end |
.define_macro(name, block) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/producer/core/recipe.rb', line 5 def define_macro(name, block) [self, Task].each do |klass| klass.class_eval do define_method(name) { |*args| task name, *args, &block } end end end |
Instance Method Details
#compose_macro(name, macro, *base_args) ⇒ Object
45 46 47 |
# File 'lib/producer/core/recipe.rb', line 45 def compose_macro(name, macro, *base_args) self.class.class_eval { compose_macro name, macro, *base_args} end |
#get(key) ⇒ Object
57 58 59 |
# File 'lib/producer/core/recipe.rb', line 57 def get(key) env[key] end |
#macro(name, &block) ⇒ Object
41 42 43 |
# File 'lib/producer/core/recipe.rb', line 41 def macro(name, &block) self.class.class_eval { define_macro name, block } end |
#set(key, value) ⇒ Object
53 54 55 |
# File 'lib/producer/core/recipe.rb', line 53 def set(key, value) env[key] = value end |
#source(filepath) ⇒ Object
29 30 31 |
# File 'lib/producer/core/recipe.rb', line 29 def source(filepath) instance_eval File.read("./#{filepath}.rb"), "#{filepath}.rb" end |
#target(hostname = nil) ⇒ Object
33 34 35 |
# File 'lib/producer/core/recipe.rb', line 33 def target(hostname = nil) if hostname then env.target ||= hostname else env.target end end |
#task(name, *args, &block) ⇒ Object
37 38 39 |
# File 'lib/producer/core/recipe.rb', line 37 def task(name, *args, &block) Task.evaluate(env, name, *args, &block).tap { |o| @tasks << o } end |
#test_macro(name, &block) ⇒ Object
49 50 51 |
# File 'lib/producer/core/recipe.rb', line 49 def test_macro(name, &block) Condition.define_test(name, block) end |