Class: Aruba::Command

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/aruba/command.rb

Overview

Command

This class is not meant for direct use - Command.new, though it’s API is public. As it is just a wrapper class, have a look at ‘BasicProcess` and the like for the public API.

See Also:

  • BasicProcess
  • SpawnProcess

Instance Method Summary collapse

Constructor Details

#initialize(command, opts = {}) ⇒ Command

Returns a new instance of Command.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/aruba/command.rb', line 25

def initialize(command, opts = {})
  launchers = []
  launchers << Processes::DebugProcess
  launchers << Processes::InProcess
  launchers << Processes::SpawnProcess

  launcher = launchers.find { |l| l.match? opts[:mode] }

  super launcher.new(
    command,
    opts.fetch(:exit_timeout),
    opts.fetch(:io_wait_timeout),
    opts.fetch(:working_directory),
    opts.fetch(:environment),
    opts.fetch(:main_class),
    opts.fetch(:stop_signal),
    opts.fetch(:startup_wait_time)
  )

  @event_bus = opts.fetch(:event_bus)
rescue KeyError => e
  raise ArgumentError, e.message
end

Instance Method Details

#startObject Also known as: run!

Start command



70
71
72
73
74
75
# File 'lib/aruba/command.rb', line 70

def start
  __getobj__.start
  event_bus.notify Events::CommandStarted.new(self)

  self
end

#stopObject

Stop command



50
51
52
53
54
55
56
57
# File 'lib/aruba/command.rb', line 50

def stop(*)
  return if __getobj__.stopped?

  __getobj__.stop
  event_bus.notify Events::CommandStopped.new(self)

  self
end

#terminateObject

Terminate command



60
61
62
63
64
65
66
67
# File 'lib/aruba/command.rb', line 60

def terminate(*)
  return if __getobj__.stopped?

  __getobj__.terminate
  event_bus.notify Events::CommandStopped.new(self)

  self
end