Class: ObjectiveCommand::Runners::Runner
- Defined in:
- lib/objective_command/runners/runner.rb
Defined Under Namespace
Classes: DebugHooker, FailureHooker, VerboseHooker
Constant Summary collapse
- @@running_options =
{ :verbose => :make_verbose, :v => :make_verbose, :raise => :raise_on_failures, :r => :raise_on_failures, :debug => :make_debug, :d => :make_debug, :mock => :make_mock, :m => :make_mock, }
Instance Attribute Summary collapse
-
#command_data_factory ⇒ Object
Accessors.
Instance Method Summary collapse
- #apply_options(*options) ⇒ Object
- #fork(data, &block) ⇒ Object
-
#initialize(*opts) ⇒ Runner
constructor
Construction methods.
- #initialize_copy(copy) ⇒ Object
- #make_debug ⇒ Object
- #make_verbose ⇒ Object
- #raise_on_failures ⇒ Object
-
#run(aCommand) ⇒ Object
Methods.
Methods included from Mockable
Methods included from Hooker
Methods included from Hookable
#disable_hook, #hook_trigger, #hooker_subscribe, #subscribe_hook
Constructor Details
Instance Attribute Details
#command_data_factory ⇒ Object
Accessors
21 22 23 |
# File 'lib/objective_command/runners/runner.rb', line 21 def command_data_factory @command_data_factory end |
Instance Method Details
#apply_options(*options) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/objective_command/runners/runner.rb', line 151 def ( * ) .flatten.each do |k| option = @@running_options[k] if option.nil? raise ArgumentError, "Bad runner option: #{k}" else send option end end self end |
#fork(data, &block) ⇒ Object
163 164 165 |
# File 'lib/objective_command/runners/runner.rb', line 163 def fork data, &block block.call end |
#initialize_copy(copy) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/objective_command/runners/runner.rb', line 57 def initialize_copy ( copy ) super if defined? @hookers @hookers = @hookers.dup else @hookers = [] end end |
#make_debug ⇒ Object
127 128 129 130 |
# File 'lib/objective_command/runners/runner.rb', line 127 def make_debug hooker_subscribe DebugHooker.new self end |
#make_verbose ⇒ Object
121 122 123 124 |
# File 'lib/objective_command/runners/runner.rb', line 121 def make_verbose hooker_subscribe VerboseHooker.new self end |
#raise_on_failures ⇒ Object
133 134 135 136 |
# File 'lib/objective_command/runners/runner.rb', line 133 def raise_on_failures hooker_subscribe FailureHooker.new self end |
#run(aCommand) ⇒ Object
Methods.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/objective_command/runners/runner.rb', line 71 def run ( aCommand ) unless aCommand.is_a? Commands::Command raise ArgumentError, "Need a OCmd::Commands::Command not #{aCommand}" end hook_trigger :display_command, aCommand data = @command_data_factory.create begin data.open_mode = @open_mode data.input = aCommand.input unless aCommand.input.nil? data.output = aCommand.output unless aCommand.output.nil? data.error = aCommand.error unless aCommand.error.nil? hook_trigger :data, aCommand, data hook_trigger :fork, data do begin hook_trigger :son, aCommand, data hook_trigger :before_open, data aCommand = aCommand.instanciate_args STDIN.reopen(data.input.to_io_for_ocmd) unless data.input.nil? STDOUT.reopen(data.output.to_io_for_ocmd) unless data.output.nil? STDERR.reopen(data.error.to_io_for_ocmd) unless data.error.nil? STDOUT.flush STDERR.flush hook_trigger :before_chdir, data Dir.chdir(aCommand.dir) unless aCommand.dir.nil? hook_trigger :before_exec, aCommand, data hook_trigger :exec, aCommand, data rescue Exception => ex hook_trigger :exception_raised_during_exec, ex end end hook_trigger :waitpid, data if data.status.nil? or not data.status.success? hook_trigger :failure, aCommand, data end hook_trigger :before_return, aCommand, data rescue Exception => ex hook_trigger :abort, data raise ex end data end |