Method: Thor::Actions#copy_file
- Defined in:
- lib/thor/actions/file_manipulation.rb
#copy_file(source, *args, &block) ⇒ Object
Copies the file from the relative source to the relative destination. If the destination is not given it’s assumed to be equal to the source.
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, and :mode => :preserve, to preserve the file mode from the source.
Examples
copy_file "README", "doc/README"
copy_file "doc/README"
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/thor/actions/file_manipulation.rb', line 20 def copy_file(source, *args, &block) config = args.last.is_a?(Hash) ? args.pop : {} destination = args.first || source source = File.(find_in_source_paths(source.to_s)) resulting_destination = create_file destination, nil, config do content = File.binread(source) content = yield(content) if block content end if config[:mode] == :preserve mode = File.stat(source).mode chmod(resulting_destination, mode, config) end end |