Class: Aggro::Subscriber
- Inherits:
-
Object
- Object
- Aggro::Subscriber
- Defined in:
- lib/aggro/subscriber.rb
Overview
Public: Subscribes to topics at a given endpoint.
Constant Summary collapse
- RAW_HANDLER =
:handle_raw
Instance Method Summary collapse
- #bind ⇒ Object
- #handle_message(message) ⇒ Object
-
#initialize(endpoint, callable = nil, &block) ⇒ Subscriber
constructor
A new instance of Subscriber.
- #stop ⇒ Object
- #subscribe_to_topic(topic) ⇒ Object
Constructor Details
#initialize(endpoint, callable = nil, &block) ⇒ Subscriber
Returns a new instance of Subscriber.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/aggro/subscriber.rb', line 6 def initialize(endpoint, callable = nil, &block) if callable @callback = callable elsif block_given? @callback = block else fail ArgumentError end @transport_sub = Aggro.transport.subscriber endpoint, method(RAW_HANDLER) @subscribed_topics = Set.new end |
Instance Method Details
#bind ⇒ Object
19 20 21 |
# File 'lib/aggro/subscriber.rb', line 19 def bind @transport_sub.start end |
#handle_message(message) ⇒ Object
23 24 25 |
# File 'lib/aggro/subscriber.rb', line 23 def () @callback.call .id, .events if .is_a? Message::Events end |
#stop ⇒ Object
27 28 29 |
# File 'lib/aggro/subscriber.rb', line 27 def stop @transport_sub.stop end |
#subscribe_to_topic(topic) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/aggro/subscriber.rb', line 31 def subscribe_to_topic(topic) return if @subscribed_topics.include? topic @subscribed_topics << topic @transport_sub.add_subscription (topic) end |