Module: Kicker::Recipes
- Defined in:
- lib/kicker/recipes.rb
Overview
:nodoc:
Defined Under Namespace
Class Method Summary collapse
- .activate_recipe(name) ⇒ Object
- .define_recipe(name, &block) ⇒ Object
- .load_recipe(name) ⇒ Object
-
.recipe(name, &block) ⇒ Object
See Kernel#recipe for more information about the usage.
- .recipe_filename(name) ⇒ Object
- .recipe_files ⇒ Object
- .recipe_names ⇒ Object
- .recipes ⇒ Object
- .reset! ⇒ Object
Class Method Details
.activate_recipe(name) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/kicker/recipes.rb', line 71 def activate_recipe(name) unless recipes.has_key?(name) load_recipe(name) end if recipe = recipes[name] recipe.call else raise ArgumentError, "Can't activate the recipe `#{name}' because it hasn't been defined yet." end end |
.define_recipe(name, &block) ⇒ Object
59 60 61 |
# File 'lib/kicker/recipes.rb', line 59 def define_recipe(name, &block) recipes[name] = block end |
.load_recipe(name) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/kicker/recipes.rb', line 63 def load_recipe(name) if recipe_names.include?(name) load recipe_filename(name) else raise LoadError, "Can't load recipe `#{name}', it doesn't exist on disk. Loadable recipes are: #{recipe_names[0..-2].join(', ')}, and #{recipe_names[-1]}" end end |
.recipe(name, &block) ⇒ Object
See Kernel#recipe for more information about the usage.
83 84 85 86 87 88 89 90 |
# File 'lib/kicker/recipes.rb', line 83 def recipe(name, &block) name = name.to_sym if block_given? define_recipe(name, &block) else activate_recipe(name) end end |
.recipe_filename(name) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/kicker/recipes.rb', line 41 def recipe_filename(name) [ USER_RECIPES_DIR, RECIPES_DIR ].each do |directory| filename = File.join(directory, "#{name}.rb") return filename if File.exist?(filename) end end |
.recipe_files ⇒ Object
55 56 57 |
# File 'lib/kicker/recipes.rb', line 55 def recipe_files Dir.glob(File.join(RECIPES_DIR, '*.rb')) + Dir.glob(File.join(USER_RECIPES_DIR, '*.rb')) end |
.recipe_names ⇒ Object
51 52 53 |
# File 'lib/kicker/recipes.rb', line 51 def recipe_names recipe_files.map { |filename| File.basename(filename, '.rb').to_sym } end |
.recipes ⇒ Object
37 38 39 |
# File 'lib/kicker/recipes.rb', line 37 def recipes @recipes ||= {} end |
.reset! ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/kicker/recipes.rb', line 29 def reset! @recipes = nil # Always load all the base recipes load_recipe :execute_cli_command load_recipe :could_not_handle_file load_recipe :dot_kick end |