Class: Brewer::Kitchen
- Inherits:
-
Object
- Object
- Brewer::Kitchen
- Defined in:
- lib/brewer/kitchen.rb
Instance Attribute Summary collapse
-
#recipe ⇒ Object
Returns the value of attribute recipe.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #clear ⇒ Object
- #clone ⇒ Object
- #delete_recipe(recipe) ⇒ Object
-
#initialize ⇒ Kitchen
constructor
A new instance of Kitchen.
- #list_recipes ⇒ Object
- #list_recipes_as_table ⇒ Object
- #load(recipe_name) ⇒ Object
- #loaded_recipe? ⇒ Boolean
- #new_recipe ⇒ Object
- #present? ⇒ Boolean
- #recipe_exists?(recipe) ⇒ Boolean
- #refresh ⇒ Object
- #store ⇒ Object
Constructor Details
Instance Attribute Details
#recipe ⇒ Object
Returns the value of attribute recipe.
6 7 8 |
# File 'lib/brewer/kitchen.rb', line 6 def recipe @recipe end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/brewer/kitchen.rb', line 6 def url @url end |
Instance Method Details
#clear ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/brewer/kitchen.rb', line 13 def clear if present? FileUtils.rm_rf(kitchen_dir) return true end false end |
#clone ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/brewer/kitchen.rb', line 21 def clone if !present? Git.clone(@url, "kitchen", :path => brewer_dir) return true end false end |
#delete_recipe(recipe) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/brewer/kitchen.rb', line 67 def delete_recipe(recipe) if recipe_exists?(recipe) File.delete(kitchen_dir(recipe + ".yml")) return true end false end |
#list_recipes ⇒ Object
75 76 77 78 79 |
# File 'lib/brewer/kitchen.rb', line 75 def list_recipes list = Dir.entries(kitchen_dir).select {|file| file.match(/\.yml/) } list.each {|recipe_name| recipe_name.slice!(".yml") } return list end |
#list_recipes_as_table ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/brewer/kitchen.rb', line 81 def list_recipes_as_table if list_recipes.empty? return "No Saved Recipes" else recipes_table_rows = list_recipes.each_slice(5).to_a recipes_table = Terminal::Table.new :title => "All Recipes", :rows => recipes_table_rows puts recipes_table return true end end |
#load(recipe_name) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/brewer/kitchen.rb', line 44 def load(recipe_name) raise "Recipe name must be a string" unless recipe_name.is_a? String raise "Recipe does not exist" unless recipe_exists?(recipe_name) @recipe = Recipe.new(recipe_name) true end |
#loaded_recipe? ⇒ Boolean
100 101 102 103 104 105 106 107 |
# File 'lib/brewer/kitchen.rb', line 100 def loaded_recipe? if @recipe if @recipe.name return true end end false end |
#new_recipe ⇒ Object
63 64 65 |
# File 'lib/brewer/kitchen.rb', line 63 def new_recipe @recipe = Recipe.new end |
#present? ⇒ Boolean
35 36 37 38 39 40 41 42 |
# File 'lib/brewer/kitchen.rb', line 35 def present? if Dir.exists?(kitchen_dir) if Dir.entries(kitchen_dir).length > 2 return true end end false end |
#recipe_exists?(recipe) ⇒ Boolean
92 93 94 95 96 97 98 |
# File 'lib/brewer/kitchen.rb', line 92 def recipe_exists?(recipe) raise "Recipe name must be a string" unless recipe.is_a? String if list_recipes.include?(recipe) return true end false end |
#refresh ⇒ Object
29 30 31 32 33 |
# File 'lib/brewer/kitchen.rb', line 29 def refresh clear clone true end |
#store ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/brewer/kitchen.rb', line 51 def store raise "Recipe not loaded. Load a recipe or create a new one" unless !@recipe.vars.empty? store = YAML::Store.new kitchen_dir(@recipe.vars['name'] + ".yml") store.transaction do @recipe.vars.each do |k, v| store[k] = v end store['created_on'] = Time.now end true end |