Class: Moqueue::MockExchange::TopicBindingKey

Inherits:
Object
  • Object
show all
Includes:
BaseKey
Defined in:
lib/moqueue/mock_exchange.rb

Instance Attribute Summary

Attributes included from BaseKey

#key

Instance Method Summary collapse

Methods included from BaseKey

#==

Constructor Details

#initialize(key_string) ⇒ TopicBindingKey

Returns a new instance of TopicBindingKey.



110
111
112
# File 'lib/moqueue/mock_exchange.rb', line 110

def initialize(key_string)
  @key = key_string.to_s.split(".")
end

Instance Method Details

#matches?(message_key) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
117
118
119
120
121
122
123
124
# File 'lib/moqueue/mock_exchange.rb', line 114

def matches?(message_key)
  message_key, binding_key = message_key.split("."), key.dup

  match = true
  while match 
    binding_token, message_token = binding_key.shift, message_key.shift
    break if (binding_token.nil? && message_token.nil?) || (binding_token == "#")
    match = ((binding_token == message_token) || (binding_token == '*') || (message_token == '*'))
  end
  match
end