Class: EpubForge::Action::RunDescription
- Inherits:
-
Object
- Object
- EpubForge::Action::RunDescription
- Defined in:
- lib/epubforge/action/run_description.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#args ⇒ Object
Returns the value of attribute args.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#execution_returned ⇒ Object
Returns the value of attribute execution_returned.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#project ⇒ Object
Returns the value of attribute project.
-
#state ⇒ Object
Returns the value of attribute state.
-
#subcommand ⇒ Object
Returns the value of attribute subcommand.
Instance Method Summary collapse
- #errors? ⇒ Boolean
- #finish ⇒ Object
- #finished? ⇒ Boolean
- #handle_errors(&block) ⇒ Object
-
#initialize ⇒ RunDescription
constructor
A new instance of RunDescription.
- #quit_on_errors ⇒ Object
- #report_errors ⇒ Object
- #run ⇒ Object
- #runnable? ⇒ Boolean
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ RunDescription
Returns a new instance of RunDescription.
13 14 15 16 17 18 19 |
# File 'lib/epubforge/action/run_description.rb', line 13 def initialize @args = nil @project = nil @action = nil @errors = [] @state = :initialized end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/epubforge/action/run_description.rb', line 4 def action @action end |
#args ⇒ Object
Returns the value of attribute args.
4 5 6 |
# File 'lib/epubforge/action/run_description.rb', line 4 def args @args end |
#errors ⇒ Object
Returns the value of attribute errors.
4 5 6 |
# File 'lib/epubforge/action/run_description.rb', line 4 def errors @errors end |
#execution_returned ⇒ Object
Returns the value of attribute execution_returned.
4 5 6 |
# File 'lib/epubforge/action/run_description.rb', line 4 def execution_returned @execution_returned end |
#namespace ⇒ Object
Returns the value of attribute namespace.
4 5 6 |
# File 'lib/epubforge/action/run_description.rb', line 4 def namespace @namespace end |
#project ⇒ Object
Returns the value of attribute project.
4 5 6 |
# File 'lib/epubforge/action/run_description.rb', line 4 def project @project end |
#state ⇒ Object
Returns the value of attribute state.
4 5 6 |
# File 'lib/epubforge/action/run_description.rb', line 4 def state @state end |
#subcommand ⇒ Object
Returns the value of attribute subcommand.
4 5 6 |
# File 'lib/epubforge/action/run_description.rb', line 4 def subcommand @subcommand end |
Instance Method Details
#errors? ⇒ Boolean
64 65 66 |
# File 'lib/epubforge/action/run_description.rb', line 64 def errors? !@errors.fwf_blank? end |
#finish ⇒ Object
76 77 78 |
# File 'lib/epubforge/action/run_description.rb', line 76 def finish @state = :finished end |
#finished? ⇒ Boolean
72 73 74 |
# File 'lib/epubforge/action/run_description.rb', line 72 def finished? @state == :finished end |
#handle_errors(&block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/epubforge/action/run_description.rb', line 39 def handle_errors &block yield rescue Exception => e @errors << "#{e.class}: #{e.}\n\t#{e.backtrace.join("\n\t")}" self end |
#quit_on_errors ⇒ Object
51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
46 47 48 49 |
# 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 ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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? ⇒ Boolean
60 61 62 |
# File 'lib/epubforge/action/run_description.rb', line 60 def runnable? ! errors? end |
#success? ⇒ Boolean
68 69 70 |
# File 'lib/epubforge/action/run_description.rb', line 68 def success? finished? && ! errors? end |
#to_s ⇒ Object
80 81 82 83 84 85 86 87 |
# 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 |