Sha256: 241475f6fb3f0d1f8b85744810ca02d745414f1cc26d999b54e1181105646641

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

RECIPES_DIR      = File.expand_path('../recipes', __FILE__)
USER_RECIPES_DIR = File.expand_path('~/.kick')

$:.unshift(RECIPES_DIR)
$:.unshift(USER_RECIPES_DIR) if File.exist?(USER_RECIPES_DIR)

module Kernel
  # If only given a <tt>name</tt>, the specified recipe will be loaded. For
  # instance, the following, in a <tt>.kick</tt> file, will load the Rails
  # recipe:
  #
  #   recipe :rails
  #
  # However, this same method is used to define a callback that is called _if_
  # the recipe is loaded. For instance, the following, in a recipe file, will
  # be called if the recipe is actually used:
  #
  #   recipe :rails do
  #     # Load anything needed for the recipe.
  #     process do
  #       # ...
  #     end
  #   end
  def recipe(name, &block)
    Kicker::Recipes.recipe(name, &block)
  end
end

class Kicker
  module Recipes #:nodoc:
    class << self
      def recipes
        @recipes ||= {}
      end
      
      def recipe(name, &block)
        name = name.to_sym
        if block_given?
          recipes[name] = block
        else
          if recipe = recipes[name]
            recipe.call
          else
            raise LoadError, "Recipe `#{name}' does not exist."
          end
        end
      end
      
      def recipe_files
        Dir.glob(File.join(RECIPES_DIR, '*.rb')) + Dir.glob(File.join(USER_RECIPES_DIR, '*.rb'))
      end
    end
    
    # We don't want this option to show up at the end
    require 'execute_cli_command'
    recipe_files.each { |file| require file }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kicker-2.3.1 lib/kicker/recipes.rb
kicker-2.3.0 lib/kicker/recipes.rb
kicker-2.2.3 lib/kicker/recipes.rb
kicker-2.2.2 lib/kicker/recipes.rb
kicker-2.2.1 lib/kicker/recipes.rb
kicker-2.2.0 lib/kicker/recipes.rb