Class: Ferrum::Browser::Subscriber

Inherits:
Object
  • Object
show all
Includes:
Concurrent::Async
Defined in:
lib/ferrum/browser/subscriber.rb

Instance Method Summary collapse

Constructor Details

#initializeSubscriber

Returns a new instance of Subscriber.



10
11
12
13
# File 'lib/ferrum/browser/subscriber.rb', line 10

def initialize
  super
  @on = Hash.new { |h, k| h[k] = [] }
end

Instance Method Details

#call(message) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/ferrum/browser/subscriber.rb', line 20

def call(message)
  method, params = message.values_at("method", "params")
  total = @on[method].size
  @on[method].each_with_index do |block, index|
    # If there are a few callback we provide current index and total
    block.call(params, index, total)
  end
end

#on(event, &block) ⇒ Object



15
16
17
18
# File 'lib/ferrum/browser/subscriber.rb', line 15

def on(event, &block)
  @on[event] << block
  true
end