lib/thor/actions/directory.rb in thor-0.11.8 vs lib/thor/actions/directory.rb in thor-0.12.0

- old
+ new

@@ -38,19 +38,20 @@ # ==== Examples # # directory "doc" # directory "doc", "docs", :recursive => false # - def directory(source, destination=nil, config={}) - action Directory.new(self, source, destination || source, config) + def directory(source, destination=nil, config={}, &block) + action Directory.new(self, source, destination || source, config, &block) end class Directory < EmptyDirectory #:nodoc: attr_reader :source - def initialize(base, source, destination=nil, config={}) + def initialize(base, source, destination=nil, config={}, &block) @source = File.expand_path(base.find_in_source_paths(source.to_s)) + @block = block super(base, destination, { :recursive => true }.merge(config)) end def invoke! base.empty_directory given_destination, config @@ -68,19 +69,22 @@ lookup = File.join(lookup, '{*,.[a-z]*}') Dir[lookup].each do |file_source| next if File.directory?(file_source) file_destination = File.join(given_destination, file_source.gsub(source, '.')) + file_destination.gsub!('/./', '/') case file_source when /\.empty_directory$/ dirname = File.dirname(file_destination).gsub(/\/\.$/, '') next if dirname == given_destination base.empty_directory(dirname, config) when /\.tt$/ - base.template(file_source, file_destination[0..-4], config) + destination = base.template(file_source, file_destination[0..-4], config) + @block.call(destination) if @block else - base.copy_file(file_source, file_destination, config) + destination = base.copy_file(file_source, file_destination, config) + @block.call(destination) if @block end end end end