Class: CrossSpec::Client
- Inherits:
-
Object
- Object
- CrossSpec::Client
- Defined in:
- lib/cross_spec/client.rb
Instance Method Summary collapse
- #broadcast(str) ⇒ Object
-
#initialize(driver, handlers = {}) ⇒ Client
constructor
A new instance of Client.
- #listen!(&block) ⇒ Object
Constructor Details
#initialize(driver, handlers = {}) ⇒ Client
Returns a new instance of Client.
3 4 5 6 |
# File 'lib/cross_spec/client.rb', line 3 def initialize(driver, handlers = {}) @driver = driver @handlers = Hash(handlers) end |
Instance Method Details
#broadcast(str) ⇒ Object
8 9 10 |
# File 'lib/cross_spec/client.rb', line 8 def broadcast(str) @driver.broadcast(str) end |
#listen!(&block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cross_spec/client.rb', line 12 def listen!(&block) @driver. do || json = JSON.parse() = if json.key?("service") ServiceMessage.from_json(json) elsif json.key?("task") TaskMessage.from_json(json) end next unless result = if block_given? yield elsif .is_a?(TaskMessage) && @handlers[.task] @handlers[.task].call() elsif .is_a?(ServiceMessage) && @handlers[.service] @handlers[.service].call() end return unless result.nil? end end |