Module: Cloudenvoy::Publisher::ClassMethods

Defined in:
lib/cloudenvoy/publisher.rb

Overview

Module class methods

Instance Method Summary collapse

Instance Method Details

#cloudenvoy_options(opts = {}) ⇒ Hash

Set the publisher runtime options.

Parameters:

  • opts (Hash) (defaults to: {})

    The publisher options.

Returns:

  • (Hash)

    The options set.



47
48
49
50
# File 'lib/cloudenvoy/publisher.rb', line 47

def cloudenvoy_options(opts = {})
  opt_list = opts&.map { |k, v| [k.to_sym, v] } || [] # symbolize
  @cloudenvoy_options_hash = Hash[opt_list]
end

#cloudenvoy_options_hashHash

Return the publisher runtime options.

Returns:

  • (Hash)

    The publisher runtime options.



57
58
59
# File 'lib/cloudenvoy/publisher.rb', line 57

def cloudenvoy_options_hash
  @cloudenvoy_options_hash || {}
end

#default_topicString

Return the default topic this publisher publishes to. Raises an error if no default topic has been defined.

Returns:

  • (String)

    The default topic.



67
68
69
# File 'lib/cloudenvoy/publisher.rb', line 67

def default_topic
  cloudenvoy_options_hash[:topic]
end

#publish(*args) ⇒ Cloudenvoy::Message

Format and publish objects to Pub/Sub.

Parameters:

  • *args (Any)

    The publisher arguments

Returns:



78
79
80
# File 'lib/cloudenvoy/publisher.rb', line 78

def publish(*args)
  new(msg_args: args).publish
end

#setupCloudenvoy::Topic

Setup the default topic for this publisher.

Returns:



87
88
89
90
91
# File 'lib/cloudenvoy/publisher.rb', line 87

def setup
  return nil unless default_topic

  PubSubClient.upsert_topic(default_topic)
end