Sha256: f8b6051a3e0af33c4d3b066ff717ff42ec0e7d025b3834d0378bb9fdb9f850f4

Contents?: true

Size: 1 KB

Versions: 10

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require "rabbit"
require "rabbit/receiving/message"
require "rabbit/receiving/handler_resolver"

class Rabbit::Receiving::Queue
  attr_reader :message, :arguments, :handler, :queue_name, :ignore_conversion

  delegate :queue, to: :handler

  def initialize(raw_message, arguments)
    @message           = Rabbit::Receiving::Message.build(raw_message, arguments)
    @handler           = Rabbit::Receiving::HandlerResolver.handler_for(message)
    @arguments         = arguments
    @queue_name        = resolved_queue_name
    @ignore_conversion = handler.ignore_queue_conversion
  end

  def name
    if queue_name
      calculated_queue_name
    else
      Rabbit.default_queue_name(ignore_conversion: ignore_conversion)
    end
  rescue
    Rabbit.default_queue_name
  end

  private

  def resolved_queue_name
    queue.is_a?(Proc) ? queue.call(message, arguments) : queue
  end

  def calculated_queue_name
    Rabbit.queue_name(queue_name, ignore_conversion: ignore_conversion)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rabbit_messaging-1.1.0 lib/rabbit/receiving/queue.rb
rabbit_messaging-1.0.0 lib/rabbit/receiving/queue.rb
rabbit_messaging-0.15.0 lib/rabbit/receiving/queue.rb
rabbit_messaging-0.13.0 lib/rabbit/receiving/queue.rb
rabbit_messaging-0.12.1 lib/rabbit/receiving/queue.rb
rabbit_messaging-0.12.0 lib/rabbit/receiving/queue.rb
rabbit_messaging-0.11.0 lib/rabbit/receiving/queue.rb
rabbit_messaging-0.10.0 lib/rabbit/receiving/queue.rb
rabbit_messaging-0.9.0 lib/rabbit/receiving/queue.rb
rabbit_messaging-0.8.1 lib/rabbit/receiving/queue.rb