Class: Aruba::CommandMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/platforms/command_monitor.rb

Overview

The command monitor is part of the private API of Aruba.

Defined Under Namespace

Classes: DefaultLastCommandStarted, DefaultLastCommandStopped

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CommandMonitor

Returns a new instance of CommandMonitor.


37
38
39
40
41
42
43
44
45
46
# File 'lib/aruba/platforms/command_monitor.rb', line 37

def initialize(opts = {})
  @registered_commands = []
  @announcer = opts.fetch(:announcer)

  @last_command_stopped = DefaultLastCommandStopped.new
  @last_command_started = DefaultLastCommandStarted.new

rescue KeyError => e
  raise ArgumentError, e.message
end

Instance Attribute Details

#last_command_startedObject

Returns the value of attribute last_command_started


15
16
17
# File 'lib/aruba/platforms/command_monitor.rb', line 15

def last_command_started
  @last_command_started
end

#last_command_stoppedObject

Returns the value of attribute last_command_stopped


48
49
50
# File 'lib/aruba/platforms/command_monitor.rb', line 48

def last_command_stopped
  @last_command_stopped
end

#registered_commandsObject (readonly)

Returns the value of attribute registered_commands


15
16
17
# File 'lib/aruba/platforms/command_monitor.rb', line 15

def registered_commands
  @registered_commands
end

Instance Method Details

#clearObject

Clear list of known commands


80
81
82
83
84
85
# File 'lib/aruba/platforms/command_monitor.rb', line 80

def clear
  registered_commands.each(&:terminate)
  registered_commands.clear

  self
end

#find(cmd) {|Command| ... } ⇒ Object

Find command

Yields:

  • (Command)

    This yields the found command


70
71
72
73
74
75
76
77
# File 'lib/aruba/platforms/command_monitor.rb', line 70

def find(cmd)
  cmd = cmd.commandline if cmd.respond_to? :commandline
  command = registered_commands.reverse.find { |c| c.commandline == cmd }

  fail CommandNotFoundError, "No command named '#{cmd}' has been started" if command.nil?

  command
end

#register_command(cmd) ⇒ Object

Register command to monitor


88
89
90
91
92
# File 'lib/aruba/platforms/command_monitor.rb', line 88

def register_command(cmd)
  registered_commands << cmd

  self
end