class EpubForge::Action::RunDescription

Attributes

action[RW]
args[RW]
errors[RW]
execution_returned[RW]
namespace[RW]
project[RW]
state[RW]
subcommand[RW]

Public Class Methods

new() click to toggle source
# File lib/epubforge/action/run_description.rb, line 13
def initialize
  @args = nil
  @project = nil
  @action = nil
  @errors = []
  @state = :initialized
end

Public Instance Methods

errors?() click to toggle source
# File lib/epubforge/action/run_description.rb, line 64
def errors?
  !@errors.fwf_blank?
end
finish() click to toggle source
# File lib/epubforge/action/run_description.rb, line 76
def finish
  @state = :finished
end
finished?() click to toggle source
# File lib/epubforge/action/run_description.rb, line 72
def finished?
  @state == :finished
end
handle_errors() { || ... } click to toggle source
# File lib/epubforge/action/run_description.rb, line 39
def handle_errors &block
  yield
rescue Exception => e
  @errors << "#{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
  self
end
quit_on_errors() click to toggle source
# File lib/epubforge/action/run_description.rb, line 51
def quit_on_errors
  if self.errors?
    self.finish
    self.report_errors
    
    exit( -1 ) unless EpubForge.gem_test_mode?
  end
end
report_errors() click to toggle source
# File lib/epubforge/action/run_description.rb, line 46
def report_errors
  puts @errors.join("\n\n------------------------------------------------------------------\n\n")
  puts "Error(s) trying to complete the requested action:"
end
run() click to toggle source
# File lib/epubforge/action/run_description.rb, line 21
def run
  if self.runnable?
    handle_errors do
      puts "Run Description: #{@args.inspect}"
      @args.shift if @args.first == self.action.keyword  # TODO: Remove this arg before getting here
      
      # If there is a project, it is sent to the action's execution as the first argument
      @args.unshift( self.project ) if self.project
      @execution_returned = self.action.run( *@args )
    end
  end

  report_errors if errors?
  
  self.finish
  self
end
runnable?() click to toggle source
# File lib/epubforge/action/run_description.rb, line 60
def runnable?
  ! errors?
end
success?() click to toggle source
# File lib/epubforge/action/run_description.rb, line 68
def success?
  finished? && ! errors?
end
to_s() click to toggle source
# File lib/epubforge/action/run_description.rb, line 80
def to_s
  str = "RunDescription:\n"
  [ :args, :project, :action, :errors, :state ].each do |data|
    str << "#{data} : #{self.send(data).inspect}\n"
  end

  str
end