Class: EpubForge::Action::RunDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/epubforge/action/run_description.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunDescription

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

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/epubforge/action/run_description.rb', line 4

def action
  @action
end

#argsObject

Returns the value of attribute args.



4
5
6
# File 'lib/epubforge/action/run_description.rb', line 4

def args
  @args
end

#errorsObject

Returns the value of attribute errors.



4
5
6
# File 'lib/epubforge/action/run_description.rb', line 4

def errors
  @errors
end

#execution_returnedObject

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

#namespaceObject

Returns the value of attribute namespace.



4
5
6
# File 'lib/epubforge/action/run_description.rb', line 4

def namespace
  @namespace
end

#projectObject

Returns the value of attribute project.



4
5
6
# File 'lib/epubforge/action/run_description.rb', line 4

def project
  @project
end

#stateObject

Returns the value of attribute state.



4
5
6
# File 'lib/epubforge/action/run_description.rb', line 4

def state
  @state
end

#subcommandObject

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

Returns:

  • (Boolean)


64
65
66
# File 'lib/epubforge/action/run_description.rb', line 64

def errors?
  !@errors.fwf_blank?
end

#finishObject



76
77
78
# File 'lib/epubforge/action/run_description.rb', line 76

def finish
  @state = :finished
end

#finished?Boolean

Returns:

  • (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.message}\n\t#{e.backtrace.join("\n\t")}"
  self
end

#quit_on_errorsObject



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_errorsObject



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

#runObject



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

Returns:

  • (Boolean)


60
61
62
# File 'lib/epubforge/action/run_description.rb', line 60

def runnable?
  ! errors?
end

#success?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/epubforge/action/run_description.rb', line 68

def success?
  finished? && ! errors?
end

#to_sObject



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