module Cloudenvoy::Subscriber::ClassMethods
Module class methods
Public Instance Methods
cloudenvoy_options(opts = {})
click to toggle source
Set the subscriber runtime options.
@param [Hash] opts The subscriber options.
@return [Hash] The options set.
# File lib/cloudenvoy/subscriber.rb, line 83 def cloudenvoy_options(opts = {}) opt_list = opts&.map { |k, v| [k.to_sym, v] } || [] # symbolize @cloudenvoy_options_hash = Hash[opt_list] end
cloudenvoy_options_hash()
click to toggle source
Return the subscriber runtime options.
@return [Hash] The subscriber runtime options.
# File lib/cloudenvoy/subscriber.rb, line 93 def cloudenvoy_options_hash @cloudenvoy_options_hash || {} end
setup()
click to toggle source
Create the Subscriber
subscription in Pub/Sub.
@return [Array<Cloudenvoy::Subscription>] The upserted subscription.
# 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)
click to toggle source
Return the subscription name used by this subscriber to subscribe to a specific topic.
@return [String] The subscription name.
# File lib/cloudenvoy/subscriber.rb, line 115 def subscription_name(topic) [ Cloudenvoy.config.gcp_sub_prefix.tr('.', '-'), to_s.underscore, topic ].join('.') end
topics()
click to toggle source
Return the list of topics this subscriber listens to.
@return [Array<Hash>] The list of subscribed topics.
# File lib/cloudenvoy/subscriber.rb, line 103 def topics @topics ||= [cloudenvoy_options_hash[:topic], cloudenvoy_options_hash[:topics]].flatten.compact.map do |t| t.is_a?(String) ? { name: t } : t end end