class BunnyMock::Exchanges::Topic

Constants

MULTI_WILDCARD

@private @return [String] Multiple subdomain wildcard

SINGLE_WILDCARD

@private @return [String] Single subdomain wildcard

Public Instance Methods

deliver(payload, opts, key) click to toggle source

Deliver a message to route with keys matching wildcards

@param [Object] payload Message content @param [Hash] opts Message properties @param [String] key Routing key

@api public

# File lib/bunny_mock/exchanges/topic.rb, line 26
def deliver(payload, opts, key)
  delivery_routes = @routes.dup.keep_if { |route, _| key =~ route_to_regex(route) }
  delivery_routes.values.flatten.each { |dest| dest.publish(payload, opts) }
end

Private Instance Methods

route_to_regex(key) click to toggle source

@private

# File lib/bunny_mock/exchanges/topic.rb, line 34
def route_to_regex(key)
  key = key.gsub('.', '\.')
  key = key.gsub(SINGLE_WILDCARD, '(?:\w+)')
  key = key.gsub(MULTI_WILDCARD, '\w+\.?')

  Regexp.new(key)
end