Module: Icalia::Event::Subscriber::ClassMethods

Defined in:
lib/icalia/event/subscriber.rb

Instance Method Summary collapse

Instance Method Details

#auto_subscribeObject



43
44
45
46
47
48
49
# File 'lib/icalia/event/subscriber.rb', line 43

def auto_subscribe
  client = Subserver::Pubsub.client
  topic = client.topic(topic_name) || client.create_topic(topic_name)

  topic.subscription(subscription_name) ||
    topic.subscribe(subscription_name)
end

#process(event_class_name, options = {}) ⇒ Object



51
52
53
54
55
# File 'lib/icalia/event/subscriber.rb', line 51

def process(event_class_name, options = {})
  return unless (processor = options.delete(:with)).present?

  processor_map[event_class_name] = processor
end

#subscribe_to_topic(new_topic_name, options = {}) ⇒ Object



34
35
36
37
# File 'lib/icalia/event/subscriber.rb', line 34

def subscribe_to_topic(new_topic_name, options = {})
  class_variable_set '@@topic_name', new_topic_name
  subserver_options options.merge(subscription: subscription_name)
end

#subscription_nameObject



39
40
41
# File 'lib/icalia/event/subscriber.rb', line 39

def subscription_name
  "#{subscription_name_prefix}-#{topic_name}"
end