Class: Chasqui::Subscriptions
- Inherits:
-
Object
- Object
- Chasqui::Subscriptions
- Defined in:
- lib/chasqui/subscriptions.rb
Instance Attribute Summary collapse
-
#queue_adapter ⇒ Object
readonly
Returns the value of attribute queue_adapter.
Instance Method Summary collapse
- #find(channel, queue) ⇒ Object
-
#initialize(queue_adapter) ⇒ Subscriptions
constructor
A new instance of Subscriptions.
- #register(subscriber) ⇒ Object
- #subscribed?(subscriber) ⇒ Boolean
- #subscribers ⇒ Object
- #unregister(subscriber) ⇒ Object
Constructor Details
#initialize(queue_adapter) ⇒ Subscriptions
Returns a new instance of Subscriptions.
5 6 7 8 9 |
# File 'lib/chasqui/subscriptions.rb', line 5 def initialize(queue_adapter) @subscriptions = {} @subscribers ||= {} @queue_adapter = queue_adapter end |
Instance Attribute Details
#queue_adapter ⇒ Object (readonly)
Returns the value of attribute queue_adapter.
3 4 5 |
# File 'lib/chasqui/subscriptions.rb', line 3 def queue_adapter @queue_adapter end |
Instance Method Details
#find(channel, queue) ⇒ Object
37 38 39 |
# File 'lib/chasqui/subscriptions.rb', line 37 def find(channel, queue) @subscriptions[queue.to_s][channel.to_s].values end |
#register(subscriber) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/chasqui/subscriptions.rb', line 11 def register(subscriber) queue = subscriber.queue.to_s channel = subscriber.channel.to_s @subscriptions[queue] ||= {} @subscriptions[queue][channel] ||= {} @subscriptions[queue][channel][subscriber.worker] = subscriber @subscribers[subscriber.worker] = subscriber queue_adapter.bind subscriber end |
#subscribed?(subscriber) ⇒ Boolean
45 46 47 |
# File 'lib/chasqui/subscriptions.rb', line 45 def subscribed?(subscriber) @subscribers.key? subscriber.worker end |
#subscribers ⇒ Object
41 42 43 |
# File 'lib/chasqui/subscriptions.rb', line 41 def subscribers @subscribers.values end |
#unregister(subscriber) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chasqui/subscriptions.rb', line 24 def unregister(subscriber) queue = subscriber.queue.to_s channel = subscriber.channel.to_s queue_adapter.unbind subscriber if @subscriptions[queue] && @subscriptions[queue][channel] @subscriptions[queue][channel].delete subscriber.worker end @subscribers.delete subscriber.worker end |