class Pandocomatic::Command

Command is a base class of all actions pandocomatic executes while converting a file or a directory of files.

@!attribute errors

@return [Error[]] list of errors created while preparing and running a
  command

@!attribute index

@return [Number] the index of this Command in the list with all commands
  to run when running pandocomatic.

Attributes

errors[R]
index[R]

Public Class Methods

new() click to toggle source

Create a new Command

# File lib/pandocomatic/command/command.rb, line 46
def initialize
  @errors = []
  @@total += 1
  @index = @@total
end
reset(configuration) click to toggle source

Reset all Commands

@param configuration [Configuration] the configuration used to convert

# File lib/pandocomatic/command/command.rb, line 55
def self.reset(configuration)
  @@src_root = configuration.src_root
  @@dry_run = configuration.dry_run?
  @@quiet = configuration.quiet?
  @@modified_only = configuration.modified_only?
  @@total = 0
end

Public Instance Methods

all_errors() click to toggle source

Get all the errors generated while executing this Command

@return [Error

# File lib/pandocomatic/command/command.rb, line 102
def all_errors
  @errors
end
count() click to toggle source

The number of commands executed by this Command; a Command can have sub commands as well.

@return [Number]

# File lib/pandocomatic/command/command.rb, line 95
def count
  1
end
directory?() click to toggle source

Is this Command converting a directory?

@return [Boolean] false

# File lib/pandocomatic/command/command.rb, line 148
def directory?
  false
end
dry_run?() click to toggle source

Does this Command not actually execute?

@return [Boolean]

# File lib/pandocomatic/command/command.rb, line 73
def dry_run?
  @@dry_run
end
errors?() click to toggle source

Has this Command run in any errors?

@return [Error

# File lib/pandocomatic/command/command.rb, line 176
def errors?
  !@errors.empty?
end
execute() click to toggle source

Execute this Command. A Command can be dry-run as well, in which it is not actually run.

# File lib/pandocomatic/command/command.rb, line 120
def execute
  description = CommandPrinter.new(self)
  Pandocomatic::LOG.info description
  description.print unless quiet?
  run if !dry_run? && runnable?
end
file_modified?(src, dst) click to toggle source

Is the source file newer than the destination file?

@param src [String] the source file @param dst [String] the destination file

@return [Boolean] True if src has been modified after dst has been last

# File lib/pandocomatic/command/command.rb, line 186
def file_modified?(src, dst)
  !File.exist? dst or File.mtime(src) > File.mtime(dst)
end
index_to_s() click to toggle source

Convert this Command’s index to a string representation

@return [String]

# File lib/pandocomatic/command/command.rb, line 114
def index_to_s
  (@@total - @index + 1).to_s.rjust(@@total.to_s.size)
end
make_quiet() click to toggle source

Make this Command run quietly

# File lib/pandocomatic/command/command.rb, line 107
def make_quiet
  @@quiet = true
end
modified_only?() click to toggle source

Is this Command only executed on modified files?

@return [Boolean]

# File lib/pandocomatic/command/command.rb, line 87
def modified_only?
  @@modified_only
end
multiple?() click to toggle source

Does this Command convert a file multiple times?

@return [Boolean] false

# File lib/pandocomatic/command/command.rb, line 155
def multiple?
  false
end
quiet?() click to toggle source

Is this Command executed silently?

@return [Boolean]

# File lib/pandocomatic/command/command.rb, line 80
def quiet?
  @@quiet
end
run() click to toggle source

Actually run this Command

# File lib/pandocomatic/command/command.rb, line 128
def run; end
runnable?() click to toggle source

Are there any errors while configuring this Command? If not, this Command is runnable.

@return [Boolean]

# File lib/pandocomatic/command/command.rb, line 134
def runnable?
  !errors?
end
skip?() click to toggle source

Will this Command be skipped, thus not executed?

@return [Boolean] false

# File lib/pandocomatic/command/command.rb, line 162
def skip?
  false
end
src_root() click to toggle source

Get the root directory of this Command’s conversion process

@return [String]

# File lib/pandocomatic/command/command.rb, line 66
def src_root
  @@src_root
end
to_s() click to toggle source

Create a String representation of this Command

@return [String]

# File lib/pandocomatic/command/command.rb, line 141
def to_s
  'command'
end
uncount() click to toggle source

Decrement the total number of conversion commands by 1

# File lib/pandocomatic/command/command.rb, line 167
def uncount
  @@total -= 1
end