Module: Kicker::Recipes
- Defined in:
- lib/kicker/recipes.rb
Overview
:nodoc:
Defined Under Namespace
Constant Summary collapse
- RECIPES_DIR =
Pathname.new('../recipes').(__FILE__)
- USER_RECIPES_DIR =
Pathname.new('~/.kick').
- CURRENT_RECIPES_DIR =
Pathname.pwd.join('.kick').
- RECIPES_DIRS =
[RECIPES_DIR, USER_RECIPES_DIR, CURRENT_RECIPES_DIR]
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
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/kicker/recipes.rb', line 74 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
62 63 64 |
# File 'lib/kicker/recipes.rb', line 62 def define_recipe(name, &block) recipes[name] = block end |
.load_recipe(name) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/kicker/recipes.rb', line 66 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.
86 87 88 89 90 91 92 93 |
# File 'lib/kicker/recipes.rb', line 86 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
44 45 46 47 48 49 50 51 52 |
# File 'lib/kicker/recipes.rb', line 44 def recipe_filename(name) [ USER_RECIPES_DIR, RECIPES_DIR ].each do |directory| filename = directory.join("#{name}.rb") return filename if filename.exist? end end |
.recipe_files ⇒ Object
58 59 60 |
# File 'lib/kicker/recipes.rb', line 58 def recipe_files RECIPES_DIRS.map{|dir| Pathname.glob(dir.join('*.rb')) }.flatten.uniq.map(&:expand_path) end |
.recipe_names ⇒ Object
54 55 56 |
# File 'lib/kicker/recipes.rb', line 54 def recipe_names recipe_files.map { |filename| filename.basename('.rb').to_s.to_sym } end |
.recipes ⇒ Object
40 41 42 |
# File 'lib/kicker/recipes.rb', line 40 def recipes @recipes ||= {} end |
.reset! ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/kicker/recipes.rb', line 32 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 |