Class: Moqueue::MockExchange::BindingKey

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_string) ⇒ BindingKey

Returns a new instance of BindingKey.



91
92
93
# File 'lib/moqueue/mock_exchange.rb', line 91

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

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



89
90
91
# File 'lib/moqueue/mock_exchange.rb', line 89

def key
  @key
end

Instance Method Details

#==(other) ⇒ Object



95
96
97
# File 'lib/moqueue/mock_exchange.rb', line 95

def ==(other)
  other.respond_to?(:key) && other.key == @key
end

#matches?(message_key) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
107
108
109
# File 'lib/moqueue/mock_exchange.rb', line 99

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