Class: Lackie::RemoteControl
- Inherits:
-
Object
- Object
- Lackie::RemoteControl
- Defined in:
- lib/lackie/remote_control.rb
Instance Method Summary collapse
- #await(expression, options = {}) ⇒ Object
- #exec(command, options = {}) ⇒ Object
-
#initialize(host, port, poller = Poller.new) ⇒ RemoteControl
constructor
A new instance of RemoteControl.
- #log(message) ⇒ Object
- #send_command(command) ⇒ Object
Constructor Details
#initialize(host, port, poller = Poller.new) ⇒ RemoteControl
Returns a new instance of RemoteControl.
7 8 9 |
# File 'lib/lackie/remote_control.rb', line 7 def initialize(host, port, poller=Poller.new) @host, @port, @poller = host, port, poller end |
Instance Method Details
#await(expression, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lackie/remote_control.rb', line 29 def await(expression, ={}) result = nil begin @poller.await("result matching expression: #{expression}", ) do begin result = exec(expression) rescue TimeoutError => e end yield result end rescue TimeoutError => e raise AwaitError.new(expression, result) end result end |
#exec(command, options = {}) ⇒ Object
15 16 17 18 |
# File 'lib/lackie/remote_control.rb', line 15 def exec(command, ={}) send_command(command) poll_for_result(command, ) end |
#log(message) ⇒ Object
11 12 13 |
# File 'lib/lackie/remote_control.rb', line 11 def log() exec("Lackie.log(#{.to_json})") end |
#send_command(command) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/lackie/remote_control.rb', line 20 def send_command(command) url = "http://#{@host}:#{@port}/lackie/eval" begin RestClient.post(url, command) rescue => e raise ConnectionError.new(url, e) end end |