Class: PubSub::Subscriber
- Inherits:
-
Object
- Object
- PubSub::Subscriber
- Defined in:
- lib/pub_sub/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
Instance Method Summary collapse
-
#initialize(options) ⇒ Subscriber
constructor
A new instance of Subscriber.
- #on_publish ⇒ Object
Constructor Details
#initialize(options) ⇒ Subscriber
Returns a new instance of Subscriber.
6 7 8 |
# File 'lib/pub_sub/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/pub_sub/subscriber.rb', line 3 def @options end |
Class Method Details
.publish(subscription) ⇒ Object
18 19 20 |
# File 'lib/pub_sub/subscriber.rb', line 18 def self.publish(subscription) subscription.on_publish end |
.subscribe_to(topic_name) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/pub_sub/subscriber.rb', line 10 def self.subscribe_to(topic_name) klass = self @subscription = PubSub.subscribe(topic_name) do |topic, | publish(klass.new()) end end |
.subscription ⇒ Object
22 23 24 |
# File 'lib/pub_sub/subscriber.rb', line 22 def self.subscription @subscription end |
.topic ⇒ Object
26 27 28 |
# File 'lib/pub_sub/subscriber.rb', line 26 def self.topic @subscription.instance_variable_get("@pattern") end |
Instance Method Details
#on_publish ⇒ Object
30 31 32 |
# File 'lib/pub_sub/subscriber.rb', line 30 def on_publish raise "Please define an on_publish method for #{self.class.name}" end |