# # 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> #

require ‘fileutils’

module Bakery

module Ingredient
  class Dir < Dir
    include Dispatcher

    def initialize path, *args, &block
      if !Dir.exists? path
        if args.include? :create_recursive
          Bakery::Log.info "creating directories: #{path}"

          FileUtils.mkdir_p path
        else
          Bakery::Log.info "creating directory: #{path}"

          FileUtils.mkdir path
        end
      end

      super path

      Dir.chdir path do
        Bakery::Log.debug "entering directory: #{path}"

        dispatch &block

        Bakery.removeMarkerLayerFromStack Dir.pwd

        Bakery::Log.debug "leaving directory: #{path}"
      end
    end
  end
end

end