Class: PubSub::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/pub_sub/subscriber.rb

Direct Known Subclasses

ActiveRecord::Subscriber

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly) Also known as: payload

Returns the value of attribute options.



3
4
5
# File 'lib/pub_sub/subscriber.rb', line 3

def options
  @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, options|
    publish(klass.new(options))
  end
end

.subscriptionObject



22
23
24
# File 'lib/pub_sub/subscriber.rb', line 22

def self.subscription
  @subscription
end

.topicObject



26
27
28
# File 'lib/pub_sub/subscriber.rb', line 26

def self.topic
  @subscription.instance_variable_get("@pattern")
end

Instance Method Details

#on_publishObject



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