Class: Playmo::Cookbook
- Inherits:
-
Object
- Object
- Playmo::Cookbook
- Includes:
- Enumerable
- 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
-
#cooked_recipes ⇒ Object
Returns the value of attribute cooked_recipes.
-
#recipes ⇒ Object
Returns the value of attribute recipes.
Class Method Summary collapse
Instance Method Summary collapse
- #[](i) ⇒ Object
- #cook_recipes!(application_name) ⇒ Object
-
#cooked?(recipe) ⇒ Boolean
Is recipe already cooked?.
- #delete(target) ⇒ Object
- #each ⇒ 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 16 |
# File 'lib/playmo/cookbook.rb', line 13 def initialize @recipes = [] @cooked_recipes = [] end |
Instance Attribute Details
#cooked_recipes ⇒ Object
Returns the value of attribute cooked_recipes.
7 8 9 |
# File 'lib/playmo/cookbook.rb', line 7 def cooked_recipes @cooked_recipes end |
#recipes ⇒ Object
Returns the value of attribute recipes.
7 8 9 |
# File 'lib/playmo/cookbook.rb', line 7 def recipes @recipes end |
Class Method Details
Instance Method Details
#[](i) ⇒ Object
30 31 32 |
# File 'lib/playmo/cookbook.rb', line 30 def [](i) recipes[i] end |
#cook_recipes!(application_name) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/playmo/cookbook.rb', line 62 def cook_recipes!(application_name) prepared_recipes = [] recipes.each do |recipe| prepared_recipes << recipe.new end prepared_recipes.each do |recipe| recipe.cook!(application_name) @cooked_recipes << recipe end end |
#cooked?(recipe) ⇒ Boolean
Is recipe already cooked?
39 40 41 |
# File 'lib/playmo/cookbook.rb', line 39 def cooked?(recipe) @cooked_recipes.include?(recipe) end |
#delete(target) ⇒ Object
34 35 36 |
# File 'lib/playmo/cookbook.rb', line 34 def delete(target) recipes.delete target end |
#each ⇒ Object
18 19 20 |
# File 'lib/playmo/cookbook.rb', line 18 def each recipes.each { |x| yield x } 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.
44 45 46 47 |
# File 'lib/playmo/cookbook.rb', line 44 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.
52 53 54 55 |
# File 'lib/playmo/cookbook.rb', line 52 def insert_after(existing_recipe, new_recipe) index = assert_index(existing_recipe, :after) insert(index + 1, new_recipe) end |
#last ⇒ Object
26 27 28 |
# File 'lib/playmo/cookbook.rb', line 26 def last recipes.last end |
#size ⇒ Object
22 23 24 |
# File 'lib/playmo/cookbook.rb', line 22 def size recipes.size end |
#use(new_recipe) ⇒ Object
Adds the new recipe at the bottom of the Cookbook stack.
58 59 60 |
# File 'lib/playmo/cookbook.rb', line 58 def use(new_recipe) recipes.push(new_recipe) end |