lib/thor/actions/directory.rb in thor-0.16.0 vs lib/thor/actions/directory.rb in thor-0.17.0
- old
+ new
@@ -36,10 +36,11 @@
# ==== Parameters
# source<String>:: the relative path to the source root.
# destination<String>:: the relative path to the destination root.
# config<Hash>:: give :verbose => false to not log the status.
# If :recursive => false, does not look for paths recursively.
+ # If :mode => :preserve, preserve the file mode from the source.
#
# ==== Examples
#
# directory "doc"
# directory "doc", "docs", :recursive => false
@@ -71,26 +72,44 @@
protected
def execute!
lookup = Util.escape_globs(source)
lookup = config[:recursive] ? File.join(lookup, '**') : lookup
- lookup = File.join(lookup, '{*,.[a-z]*}')
+ lookup = file_level_lookup(lookup)
- Dir[lookup].sort.each do |file_source|
+ files(lookup).sort.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$/
- destination = base.template(file_source, file_destination[0..-4], config, &@block)
- else
- destination = base.copy_file(file_source, file_destination, config, &@block)
+ when /\.empty_directory$/
+ dirname = File.dirname(file_destination).gsub(/\/\.$/, '')
+ next if dirname == given_destination
+ base.empty_directory(dirname, config)
+ when /\.tt$/
+ destination = base.template(file_source, file_destination[0..-4], config, &@block)
+ else
+ destination = base.copy_file(file_source, file_destination, config, &@block)
end
+ end
+ end
+
+ if RUBY_VERSION < '2.0'
+ def file_level_lookup(previous_lookup)
+ File.join(previous_lookup, '{*,.[a-z]*}')
+ end
+
+ def files(lookup)
+ Dir[lookup]
+ end
+ else
+ def file_level_lookup(previous_lookup)
+ File.join(previous_lookup, '*')
+ end
+
+ def files(lookup)
+ Dir.glob(lookup, File::FNM_DOTMATCH)
end
end
end
end