Class: Surfliner::Mq::TopicConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/surfliner/mq/topic_config.rb

Overview

Encapsulates topic configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, options: {}) ⇒ TopicConfig

Returns a new instance of TopicConfig.

Parameters:

  • name (String)

    topic exchange to listen to

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

    RabbitMQ topic options. (See Bunny::Channel#topic)



13
14
15
16
# File 'lib/surfliner/mq/topic_config.rb', line 13

def initialize(name:, options: {})
  @name = name
  @options = options
end

Instance Attribute Details

#nameString (readonly)

Returns The topic exchange to listen to.

Returns:

  • (String)

    The topic exchange to listen to



6
7
8
# File 'lib/surfliner/mq/topic_config.rb', line 6

def name
  @name
end

#optionsHash (readonly)

Returns RabbitMQ topic options. (See Bunny::Channel#topic).

Returns:

  • (Hash)

    RabbitMQ topic options. (See Bunny::Channel#topic)



9
10
11
# File 'lib/surfliner/mq/topic_config.rb', line 9

def options
  @options
end

Class Method Details

.from_env(**options) ⇒ TopicConfig

Returns a default (environment-variable-based) configuration with the specified options.

Variable Sample value Description
RABBITMQ_TOPIC surfliner.metadata RabbitMQ topic name

Parameters:

  • options (Hash)

    RabbitMQ topic options. (See Bunny::Channel#topic)

Returns:



52
53
54
55
56
57
# File 'lib/surfliner/mq/topic_config.rb', line 52

def from_env(**options)
  TopicConfig.new(
    name: ENV.fetch("RABBITMQ_TOPIC"),
    options:
  )
end

Instance Method Details

#==(other) ⇒ Boolean

Whether other represents the same configuration as this object. Note that if name or options are modified, equality becomes unstable.

Parameters:

  • other (Object, nil)

    the object to compare

Returns:

  • (Boolean)

    true if other represents the same configuration as this object, false otherwise



30
31
32
33
# File 'lib/surfliner/mq/topic_config.rb', line 30

def ==(other)
  return unless other.class == self.class
  other.name == name && other.options == options
end

#eql?(other) ⇒ Boolean

Whether other represents the same configuration as this object. Note that if name or options are modified, equality becomes unstable.

Parameters:

  • other (Object, nil)

    the object to compare

Returns:

  • (Boolean)

    true if other represents the same configuration as this object, false otherwise



22
23
24
# File 'lib/surfliner/mq/topic_config.rb', line 22

def eql?(other)
  self == other
end

#hashInteger

The hash value of this object. Equal configurations will have equal hash values. Note that if name or options are modified, the hash value becomes unstable.

Returns:

  • (Integer)

    a hash value suitable for using equal configs as hash keys



38
39
40
# File 'lib/surfliner/mq/topic_config.rb', line 38

def hash
  [name, options].hash
end