Class: Shoryuken::Polling::QueueConfiguration

Inherits:
Struct
  • Object
show all
Defined in:
lib/shoryuken/polling/queue_configuration.rb

Overview

Configuration object representing a queue and its associated options.

This class encapsulates a queue name along with any polling-specific options or metadata. It provides a structured way to pass queue information between polling strategies and the message fetching system.

The class extends Struct to provide attribute accessors for name and options while adding custom behavior for equality comparison and string representation.

Examples:

Creating a basic queue configuration

config = QueueConfiguration.new('my_queue', {})
config.name     # => 'my_queue'
config.options  # => {}

Creating a queue configuration with options

config = QueueConfiguration.new('priority_queue', { priority: :high })
config.name     # => 'priority_queue'
config.options  # => { priority: :high }

Comparing configurations

config1 = QueueConfiguration.new('queue', {})
config2 = QueueConfiguration.new('queue', {})
config1 == config2  # => true
config1 == 'queue'  # => true (when options are empty)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameString (readonly)

The name of the queue

Returns:

  • (String)

    the current value of name



32
33
34
# File 'lib/shoryuken/polling/queue_configuration.rb', line 32

def name
  @name
end

#optionsHash (readonly)

Additional options or metadata for the queue

Returns:

  • (Hash)

    the current value of options



32
33
34
# File 'lib/shoryuken/polling/queue_configuration.rb', line 32

def options
  @options
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Compares this configuration with another object for equality.

Two QueueConfiguration objects are equal if they have the same name and options. For convenience, a configuration with empty options can also be compared directly with a string queue name.

Examples:

Comparing with another QueueConfiguration

config1 = QueueConfiguration.new('queue', {})
config2 = QueueConfiguration.new('queue', {})
config1 == config2  # => true

Comparing with a string (only when options are empty)

config = QueueConfiguration.new('queue', {})
config == 'queue'  # => true

config_with_options = QueueConfiguration.new('queue', { weight: 5 })
config_with_options == 'queue'  # => false

Parameters:

  • other (Object)

    The object to compare with

Returns:

  • (Boolean)

    true if the objects are considered equal



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/shoryuken/polling/queue_configuration.rb', line 64

def ==(other)
  case other
  when String
    if options.empty?
      name == other
    else
      false
    end
  else
    super
  end
end

#hashInteger

Generates a hash value based on the queue name.

This method ensures that QueueConfiguration objects can be used as hash keys and that configurations with the same queue name will have the same hash value regardless of their options.

Returns:

  • (Integer)

    Hash value based on the queue name



40
41
42
# File 'lib/shoryuken/polling/queue_configuration.rb', line 40

def hash
  name.hash
end

#to_sString

Returns a string representation of the queue configuration.

For configurations with empty options, returns just the queue name. For configurations with options, returns a detailed representation showing both the name and the options hash.

Examples:

Simple queue without options

config = QueueConfiguration.new('simple_queue', {})
config.to_s  # => 'simple_queue'

Queue with options

config = QueueConfiguration.new('complex_queue', { priority: :high })
config.to_s  # => '#<QueueConfiguration complex_queue options={:priority=>:high}>'

Returns:

  • (String)

    String representation of the configuration



94
95
96
97
98
99
100
# File 'lib/shoryuken/polling/queue_configuration.rb', line 94

def to_s
  if options&.empty?
    name
  else
    "#<QueueConfiguration #{name} options=#{options.inspect}>"
  end
end