Sha256: 095bfb04fc9391ce5d29299ec32b73141eff7566e151791c09c34135438e3630

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Sidekiq
  module Throttled
    # Queue name utility belt.
    #
    # @private
    module QueueName
      # RegExp used to stip out any redisr-namespace prefixes with `queue:`.
      QUEUE_NAME_PREFIX_RE = /^.*queue:/
      private_constant :QUEUE_NAME_PREFIX_RE

      class << self
        # Strips redis-namespace and `queue:` prefix from given queue name.
        #
        # @example
        #
        #   QueueName.normalize "queue:default"
        #   # => "default"
        #
        #   QueueName.normalize "queue:queue:default"
        #   # => "default"
        #
        #   QueueName.normalize "foo:bar:queue:default"
        #   # => "default"
        #
        # @param [String]
        # @return [String]
        def normalize(queue)
          queue.sub(QUEUE_NAME_PREFIX_RE, "".freeze)
        end

        # Prepends `queue:` prefix to given `queue` name.
        #
        # @note It does not normalizes queue before expanding it, thus
        #   double-call of this method will potentially do some harm.
        #
        # @param [String] queue Queue name
        # @return [String]
        def expand(queue)
          "queue:#{queue}".freeze
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sidekiq-throttled-0.6.6 lib/sidekiq/throttled/queue_name.rb
sidekiq-throttled-0.6.5 lib/sidekiq/throttled/queue_name.rb
sidekiq-throttled-0.6.4 lib/sidekiq/throttled/queue_name.rb
sidekiq-throttled-0.6.3 lib/sidekiq/throttled/queue_name.rb
sidekiq-throttled-0.6.2 lib/sidekiq/throttled/queue_name.rb
sidekiq-throttled-0.6.1 lib/sidekiq/throttled/queue_name.rb
sidekiq-throttled-0.6.0 lib/sidekiq/throttled/queue_name.rb