Class: Playmo::Cookbook
- Includes:
- Enumerable, Singleton
- Defined in:
- lib/playmo/cookbook.rb
Overview
This class contains all registered recipes. You can register own recipe in this class
Instance Attribute Summary collapse
-
#recipes ⇒ Object
Returns the value of attribute recipes.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #cook_recipes!(application_name, options) ⇒ Object
- #delete(target) ⇒ Object
- #delete_all ⇒ Object
- #each ⇒ Object
- #find_recipe(recipe_symbol) ⇒ Object
-
#initialize ⇒ Cookbook
constructor
A new instance of Cookbook.
-
#insert(existing_recipe, new_recipe) ⇒ Object
(also: #insert_before)
Adds the new recipe before the specified existing recipe in the Cookbook stack.
-
#insert_after(existing_recipe, new_recipe) ⇒ Object
Adds the new recipe after the specified existing recipe in the Cookbook stack.
- #last ⇒ Object
- #size ⇒ Object
-
#use(new_recipe) ⇒ Object
Adds the new recipe at the bottom of the Cookbook stack.
Constructor Details
#initialize ⇒ Cookbook
Returns a new instance of Cookbook.
13 14 15 |
# File 'lib/playmo/cookbook.rb', line 13 def initialize @recipes = [] end |
Instance Attribute Details
#recipes ⇒ Object
Returns the value of attribute recipes.
11 12 13 |
# File 'lib/playmo/cookbook.rb', line 11 def recipes @recipes end |
Instance Method Details
#[](i) ⇒ Object
29 30 31 |
# File 'lib/playmo/cookbook.rb', line 29 def [](i) recipes[i] end |
#cook_recipes!(application_name, options) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/playmo/cookbook.rb', line 60 def cook_recipes!(application_name, ) recipes.each { |recipe| recipe.cook!(application_name) } if ['dry-run'] puts "Recipes execution order:" recipes.each_with_index { |recipe, i| puts "#{i+1}. #{recipe.name}" } else Playmo::Action.execute_all # Execute all actions end end |
#delete(target) ⇒ Object
33 34 35 |
# File 'lib/playmo/cookbook.rb', line 33 def delete(target) recipes.delete target end |
#delete_all ⇒ Object
37 38 39 |
# File 'lib/playmo/cookbook.rb', line 37 def delete_all self.recipes = [] end |
#each ⇒ Object
17 18 19 |
# File 'lib/playmo/cookbook.rb', line 17 def each recipes.each { |x| yield x } end |
#find_recipe(recipe_symbol) ⇒ Object
71 72 73 |
# File 'lib/playmo/cookbook.rb', line 71 def find_recipe(recipe_symbol) recipes.find { |recipe| recipe.name == recipe_symbol } end |
#insert(existing_recipe, new_recipe) ⇒ Object Also known as: insert_before
Adds the new recipe before the specified existing recipe in the Cookbook stack.
42 43 44 45 |
# File 'lib/playmo/cookbook.rb', line 42 def insert(existing_recipe, new_recipe) index = assert_index(existing_recipe, :before) recipes.insert(index, new_recipe) end |
#insert_after(existing_recipe, new_recipe) ⇒ Object
Adds the new recipe after the specified existing recipe in the Cookbook stack.
50 51 52 53 |
# File 'lib/playmo/cookbook.rb', line 50 def insert_after(existing_recipe, new_recipe) index = assert_index(existing_recipe, :after) insert(index + 1, new_recipe) end |
#last ⇒ Object
25 26 27 |
# File 'lib/playmo/cookbook.rb', line 25 def last recipes.last end |
#size ⇒ Object
21 22 23 |
# File 'lib/playmo/cookbook.rb', line 21 def size recipes.size end |
#use(new_recipe) ⇒ Object
Adds the new recipe at the bottom of the Cookbook stack.
56 57 58 |
# File 'lib/playmo/cookbook.rb', line 56 def use(new_recipe) recipes.push(new_recipe) end |