Class: Ferrum::Browser::Subscriber
- Inherits:
-
Object
- Object
- Ferrum::Browser::Subscriber
- Includes:
- Concurrent::Async
- Defined in:
- lib/ferrum/browser/subscriber.rb
Instance Method Summary collapse
- #call(message) ⇒ Object
-
#initialize ⇒ Subscriber
constructor
A new instance of Subscriber.
- #on(event, &block) ⇒ Object
Constructor Details
#initialize ⇒ Subscriber
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() method, params = .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 |