Class: SubPub::Subscriber
- Inherits:
-
Object
- Object
- SubPub::Subscriber
- Defined in:
- lib/sub_pub/subscriber.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
(also: #payload)
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .publish(subscription) ⇒ Object
- .subscribe_to(topic_name) ⇒ Object
- .subscription ⇒ Object
- .topic ⇒ Object
- .topic_name ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Subscriber
constructor
A new instance of Subscriber.
- #on_publish ⇒ Object
- #topic_name ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Subscriber
Returns a new instance of Subscriber.
6 7 8 |
# File 'lib/sub_pub/subscriber.rb', line 6 def initialize(={}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly) Also known as: payload
Returns the value of attribute options.
3 4 5 |
# File 'lib/sub_pub/subscriber.rb', line 3 def @options end |
Class Method Details
.publish(subscription) ⇒ Object
20 21 22 |
# File 'lib/sub_pub/subscriber.rb', line 20 def self.publish(subscription) subscription.on_publish end |
.subscribe_to(topic_name) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/sub_pub/subscriber.rb', line 10 def self.subscribe_to(topic_name) if subscription.present? SubPub.unsubscribe(subscription) end @subscription = SubPub.subscribe(topic_name) do |topic, | publish(new()) end end |
.subscription ⇒ Object
24 25 26 |
# File 'lib/sub_pub/subscriber.rb', line 24 def self.subscription @subscription end |
.topic ⇒ Object
28 29 30 |
# File 'lib/sub_pub/subscriber.rb', line 28 def self.topic @subscription.topic end |
.topic_name ⇒ Object
32 33 34 |
# File 'lib/sub_pub/subscriber.rb', line 32 def self.topic_name topic end |
Instance Method Details
#on_publish ⇒ Object
40 41 42 |
# File 'lib/sub_pub/subscriber.rb', line 40 def on_publish raise "Please define an on_publish method for #{self.class.name}" end |
#topic_name ⇒ Object
36 37 38 |
# File 'lib/sub_pub/subscriber.rb', line 36 def topic_name self.class.topic_name end |