Class: Playmo::Cookbook

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCookbook

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_recipesObject

Returns the value of attribute cooked_recipes.



7
8
9
# File 'lib/playmo/cookbook.rb', line 7

def cooked_recipes
  @cooked_recipes
end

#recipesObject

Returns the value of attribute recipes.



7
8
9
# File 'lib/playmo/cookbook.rb', line 7

def recipes
  @recipes
end

Class Method Details

.instanceObject



9
10
11
# File 'lib/playmo/cookbook.rb', line 9

def self.instance
  @@instance ||= Playmo::Cookbook.new
end

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?

Returns:

  • (Boolean)


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

#eachObject



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

#lastObject



26
27
28
# File 'lib/playmo/cookbook.rb', line 26

def last
  recipes.last
end

#sizeObject



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