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.



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

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

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

Instance Method Details

#==(other) ⇒ Object



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

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

#matches?(message_key) ⇒ Boolean

Returns:

  • (Boolean)


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

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