Module: Cloudenvoy::Subscriber::ClassMethods
- Defined in:
- lib/cloudenvoy/subscriber.rb
Overview
Module class methods
Instance Method Summary collapse
-
#cloudenvoy_options(opts = {}) ⇒ Hash
Set the subscriber runtime options.
-
#cloudenvoy_options_hash ⇒ Hash
Return the subscriber runtime options.
-
#setup ⇒ Array<Cloudenvoy::Subscription>
Create the Subscriber subscription in Pub/Sub.
-
#subscription_name(topic) ⇒ String
Return the subscription name used by this subscriber to subscribe to a specific topic.
-
#topics ⇒ Array<Hash>
Return the list of topics this subscriber listens to.
Instance Method Details
#cloudenvoy_options(opts = {}) ⇒ Hash
Set the subscriber runtime options.
83 84 85 86 |
# File 'lib/cloudenvoy/subscriber.rb', line 83 def (opts = {}) opt_list = opts&.map { |k, v| [k.to_sym, v] } || [] # symbolize @cloudenvoy_options_hash = Hash[opt_list] end |
#cloudenvoy_options_hash ⇒ Hash
Return the subscriber runtime options.
93 94 95 |
# File 'lib/cloudenvoy/subscriber.rb', line 93 def @cloudenvoy_options_hash || {} end |
#setup ⇒ Array<Cloudenvoy::Subscription>
Create the Subscriber subscription in Pub/Sub.
128 129 130 131 132 133 134 |
# File 'lib/cloudenvoy/subscriber.rb', line 128 def setup topics.map do |t| topic_name = t[:name] || t['name'] sub_opts = t.reject { |k, _| k.to_sym == :name } PubSubClient.upsert_subscription(topic_name, subscription_name(topic_name), sub_opts) end end |
#subscription_name(topic) ⇒ String
Return the subscription name used by this subscriber to subscribe to a specific topic.
115 116 117 118 119 120 121 |
# File 'lib/cloudenvoy/subscriber.rb', line 115 def subscription_name(topic) [ Cloudenvoy.config.gcp_sub_prefix.tr('.', '-'), to_s.underscore, topic ].join('.') end |
#topics ⇒ Array<Hash>
Return the list of topics this subscriber listens to.
103 104 105 106 107 |
# File 'lib/cloudenvoy/subscriber.rb', line 103 def topics @topics ||= [[:topic], [:topics]].flatten.compact.map do |t| t.is_a?(String) ? { name: t } : t end end |