Sha256: 413b82455e96ba993520cd84aa0f0af159fa7d0da07d455cbc1e9c901424b8e4

Contents?: true

Size: 1.03 KB

Versions: 24

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true
module Msgr
  class Route
    attr_reader :consumer, :action, :opts

    MATCH_REGEXP = /\A(?<consumer>\w+)#(?<action>\w+)\z/

    # rubocop:disable Metrics/AbcSize
    # rubocop:disable Metrics/MethodLength
    def initialize(key, opts = {})
      @opts = opts
      raise ArgumentError.new 'Missing `to` options.' unless @opts[:to]

      add key

      result = MATCH_REGEXP.match(opts[:to].strip.to_s)

      unless result
        raise ArgumentError.new \
          "Invalid consumer format: #{opts[:to].strip.to_s.inspect}. " \
          'Must be `consumer_class#action`.'
      end

      @consumer = "#{result[:consumer].camelize}Consumer"
      @action   = result[:action].underscore
    end

    def keys
      @keys ||= []
    end
    alias routing_keys keys

    def add(key)
      raise ArgumentError.new 'Routing key required.' unless key.present?

      keys << key
    end

    def accept?(_key, opts)
      self.opts == opts
    end

    def name
      "msgr.consumer.#{consumer}.#{action}"
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
msgr-0.15.2.1.b157 lib/msgr/route.rb
msgr-0.15.2.1.b156 lib/msgr/route.rb
msgr-0.15.2.1.b155 lib/msgr/route.rb
msgr-0.15.2.1.b154 lib/msgr/route.rb
msgr-0.15.2.1.b152 lib/msgr/route.rb
msgr-0.15.1.1.b151 lib/msgr/route.rb
msgr-0.15.2 lib/msgr/route.rb
msgr-0.15.1.1.b150 lib/msgr/route.rb
msgr-0.15.1.1.b146 lib/msgr/route.rb
msgr-0.15.1.1.b145 lib/msgr/route.rb
msgr-0.15.1.1.b144 lib/msgr/route.rb
msgr-0.15.1.1.b143 lib/msgr/route.rb
msgr-0.15.1.1.b141 lib/msgr/route.rb
msgr-0.15.0.1.b140 lib/msgr/route.rb
msgr-0.15.1 lib/msgr/route.rb
msgr-0.15.0.1.b139 lib/msgr/route.rb
msgr-0.15.0.1.b136 lib/msgr/route.rb
msgr-0.15.0.1.b135 lib/msgr/route.rb
msgr-0.15.0.1.b134 lib/msgr/route.rb
msgr-0.15.0.1.b131 lib/msgr/route.rb