# # Copyright © 2013 # Nathan Currier # # Use, modification, and distribution are all subject to the # Boost Software License, Version 1.0. (See the accompanying # file LICENSE.md or at rideliner.tk/LICENSE.html). # # <description> #

module Bakery

module Ingredient
  class Project < Dir
    def initialize name, *args, &block
      if name.is_a? Hash
        fail "Project Argument Error" if name.size != 1

        projname, recipe = name.map { |k, v| [k, v] }.first
      else
        projname, recipe = name.to_s, nil
      end

      super projname, *args do
        Bakery.addCake

        if recipe
          # if an external recipe is specified, load it
          extern_recipe_loc = File.join(Bakery::ROOT_DIR, recipe)
          load extern_recipe_loc
        end

        local_recipe_loc = File.join(Dir.pwd, '.recipe')

        # load .recipe if it isn't the external recipe and it exists
        if local_recipe_loc != extern_recipe_loc
          load_if_exists local_recipe_loc
        end

        dispatch &block

        Bakery.removeCake
      end
    end
  end
end

end