Class: Playmo::Cookbook

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

Instance Method Summary collapse

Constructor Details

#initializeCookbook

Returns a new instance of Cookbook.



13
14
15
# File 'lib/playmo/cookbook.rb', line 13

def initialize
  @recipes = []
end

Instance Attribute Details

#recipesObject

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, options)
  recipes.each { |recipe| recipe.cook!(application_name) }

  if options['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_allObject



37
38
39
# File 'lib/playmo/cookbook.rb', line 37

def delete_all
  self.recipes = []
end

#eachObject



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

#lastObject



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

def last
  recipes.last
end

#sizeObject



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