class Pandocomatic::CopyFileCommand

A command to copy a file

@!attribute src

@return [String] path to the file to copy

Attributes

src[R]

Public Class Methods

new(src, dst) click to toggle source

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

Calls superclass method Pandocomatic::Command::new
# 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

Public Instance Methods

run() click to toggle source

Run this CopyFileCommand

# File lib/pandocomatic/command/copy_file_command.rb, line 47
def run
  if file_modified?(@src, @dst)
    Pandocomatic::LOG.info "Copying '#{@src}' → '#{@dst}'"
    FileUtils.cp(@src, @dst)
  end
rescue StandardError => e
  raise IOError.new(:unable_to_copy_file, e, [@src, @dst])
end
to_s() click to toggle source

A string representation of this CopyFileCommand

@return [String]

# File lib/pandocomatic/command/copy_file_command.rb, line 59
def to_s
  "copy #{File.basename @src}"
end