class Pandocomatic::CreateLinkCommand

A command to create a link to a file

@!attribute src

@return [String] the path to the file to link to

@!attribute dst

@return [String] the link name to create

@!attribute dst_target

@return [String] the link in the destination tree to link to

Attributes

dst[R]
dst_target[R]
src[R]

Public Class Methods

new(src, dst) click to toggle source

Create a new CreateLinkCommand

@param src [String] the path to the file to link @param dst [String] the path to the name of the link to create

Calls superclass method Pandocomatic::Command::new
# File lib/pandocomatic/command/create_link_command.rb, line 45
def initialize(src, dst)
  super()
  @src = src
  begin
    src_target = File.readlink @src

    if src_target.start_with? '.'
      full_src_target = File.expand_path src_target, File.dirname(src)

      if full_src_target.start_with? src_root
        @dst = dst
        @dst_target = src_target
      else
        WarningPrinter.new(Warning.new(:skipping_link_because_it_points_outside_the_source_tree, @src)).print
      end

      uncount if skip?
    end
  rescue StandardError => e
    @errors.push IOError.new(:unable_to_read_symbolic_link, e, @src)
  end
end

Public Instance Methods

modified?() click to toggle source

Has the source file been modified?

@return [Boolean]

# File lib/pandocomatic/command/create_link_command.rb, line 101
def modified?
  if File.exist? @dst
    absolute_dst = File.realpath @dst
    target = File.expand_path(@dst_target, absolute_dst)
    absolute_dst != target
  else
    true
  end
end
run() click to toggle source

Run this CreateLinkCommand

# File lib/pandocomatic/command/create_link_command.rb, line 69
def run
  unless File.exist? @dst
    File.symlink @dst_target, @dst
    Pandocomatic::LOG.info "Creating symlink '#{@dst_target}' → '#{@dst}'"
  end
rescue StandardError => e
  raise IOError.new(:unable_to_create_symbolic_link, e, [@src, @dst])
end
runnable?() click to toggle source

Can this CreateLinkCommand be run?

@return [Boolean] True if there are no errors and both source and

destination do exist
# File lib/pandocomatic/command/create_link_command.rb, line 82
def runnable?
  !(errors? or @dst.nil? or @dst_target.nil? or @src.nil?)
end
skip?() click to toggle source

Should this CreateLinkCommand be skipped?

@return [Boolean]

# File lib/pandocomatic/command/create_link_command.rb, line 94
def skip?
  !modified_only? or !modified?
end
to_s() click to toggle source

Create a string representation of this CreateLinkCommand

# File lib/pandocomatic/command/create_link_command.rb, line 87
def to_s
  "link #{File.basename @dst} -> #{@dst_target}"
end