Class: Vli::Action::Runner
- Inherits:
-
Object
- Object
- Vli::Action::Runner
- Defined in:
- lib/vli/action/runner.rb
Constant Summary collapse
- @@reported_interrupt =
false
Instance Method Summary collapse
- #exit_immediately_message ⇒ Object
-
#initialize(registry, globals = nil, &block) ⇒ Runner
constructor
A new instance of Runner.
- #run(callable_id, options = nil) ⇒ Object
- #waiting_cleanup_message ⇒ Object
Constructor Details
#initialize(registry, globals = nil, &block) ⇒ Runner
Returns a new instance of Runner.
9 10 11 12 13 |
# File 'lib/vli/action/runner.rb', line 9 def initialize(registry, globals=nil, &block) @registry = registry @globals = globals || {} @lazy_globals = block end |
Instance Method Details
#exit_immediately_message ⇒ Object
46 47 48 |
# File 'lib/vli/action/runner.rb', line 46 def "Exiting immediately, without cleanup!" end |
#run(callable_id, options = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vli/action/runner.rb', line 15 def run(callable_id, =nil) callable = callable_id callable = Builder.new.use(callable_id) if callable_id.kind_of?(Class) callable = @registry.get(callable_id) if callable_id.kind_of?(Symbol) raise ArgumentError, "Argument to run must be a callable object or registered action." if !callable || !callable.respond_to?(:call) # Create the initial environment with the options given environment = Environment.new environment.merge!(@globals) environment.merge!(@lazy_globals.call) if @lazy_globals environment.merge!( || {}) # Run the action chain in a busy block, marking the environment as # interrupted if a SIGINT occurs, and exiting cleanly once the # chain has been run. ui = environment[:ui] if environment.has_key?(:ui) int_callback = lambda do if environment[:interrupted] ui.error if ui abort end ui.warn if ui && !@@reported_interrupt environment[:interrupted] = true @@reported_interrupt = true end # We place a process lock around every action that is called Util::Busy.busy(int_callback) { callable.call(environment) } end |
#waiting_cleanup_message ⇒ Object
50 51 52 |
# File 'lib/vli/action/runner.rb', line 50 def "Waiting for cleanup before exiting..." end |