Class: Pandocomatic::CopyFileCommand
- Defined in:
- lib/pandocomatic/command/copy_file_command.rb
Overview
A command to copy a file
Instance Attribute Summary collapse
-
#src ⇒ String
Path to the file to copy.
Attributes inherited from Command
Instance Method Summary collapse
-
#initialize(src, dst) ⇒ CopyFileCommand
constructor
Create a new CopyFileCommand.
-
#run ⇒ Object
Run this CopyFileCommand.
-
#to_s ⇒ String
A string representation of this CopyFileCommand.
Methods inherited from Command
#all_errors, #count, #debug?, #directory?, #dry_run?, #errors?, #execute, #file_modified?, #index_to_s, #make_quiet, #modified_only?, #multiple?, #quiet?, reset, #runnable?, #skip?, #src_root, #uncount
Constructor Details
#initialize(src, dst) ⇒ CopyFileCommand
Create a new CopyFileCommand
38 39 40 41 42 43 44 |
# File 'lib/pandocomatic/command/copy_file_command.rb', line 38 def initialize(src, dst) super() @src = src @dst = dst @errors.push IOError.new(:file_is_not_readable, nil, @src) unless File.readable? @src @errors.push IOError.new(:file_is_not_writable, nil, @dst) unless !File.exist?(@dst) || File.writable?(@dst) end |
Instance Attribute Details
#src ⇒ String
Returns path to the file to copy.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pandocomatic/command/copy_file_command.rb', line 31 class CopyFileCommand < Command attr_reader :src # Create a new CopyFileCommand # # @param src [String] path to the file to copy # @param dst [String] path to the place to copy the source file to def initialize(src, dst) super() @src = src @dst = dst @errors.push IOError.new(:file_is_not_readable, nil, @src) unless File.readable? @src @errors.push IOError.new(:file_is_not_writable, nil, @dst) unless !File.exist?(@dst) || File.writable?(@dst) end # Run this CopyFileCommand def run FileUtils.cp(@src, @dst) if file_modified?(@src, @dst) rescue StandardError => e raise IOError.new(:unable_to_copy_file, e, [@src, @dst]) end # A string representation of this CopyFileCommand # # @return [String] def to_s "copy #{File.basename @src}" end end |
Instance Method Details
#run ⇒ Object
Run this CopyFileCommand
47 48 49 50 51 |
# File 'lib/pandocomatic/command/copy_file_command.rb', line 47 def run FileUtils.cp(@src, @dst) if file_modified?(@src, @dst) rescue StandardError => e raise IOError.new(:unable_to_copy_file, e, [@src, @dst]) end |
#to_s ⇒ String
A string representation of this CopyFileCommand
56 57 58 |
# File 'lib/pandocomatic/command/copy_file_command.rb', line 56 def to_s "copy #{File.basename @src}" end |