Class: MarchHareMock::Exchange

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = 'default.exchange', attrs = {}) ⇒ Exchange

Returns a new instance of Exchange.



101
102
103
104
105
# File 'lib/march_hare_mock.rb', line 101

def initialize(name = 'default.exchange', attrs = {})
  self.name   = name
  self.attrs  = attrs.dup
  self.queues = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/march_hare_mock.rb', line 115

def method_missing(method, *args)
  method_name  = method.to_s
  is_predicate = false
  if method_name =~ /^(.*)\?$/
    key           = $1.to_sym
    is_predicate = true
  else
    key = method.to_sym
  end

  if attrs.has_key? key
    value = attrs[key]
    is_predicate ? !!value : value
  else
    super
  end
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



99
100
101
# File 'lib/march_hare_mock.rb', line 99

def attrs
  @attrs
end

#nameObject

Returns the value of attribute name.



99
100
101
# File 'lib/march_hare_mock.rb', line 99

def name
  @name
end

#queuesObject

Returns the value of attribute queues.



99
100
101
# File 'lib/march_hare_mock.rb', line 99

def queues
  @queues
end

Instance Method Details

#bound_to?(queue_name) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/march_hare_mock.rb', line 111

def bound_to?(queue_name)
  queues.any?{|q| q.name == queue_name}
end

#publish(msg, msg_attrs = {}) ⇒ Object



107
108
109
# File 'lib/march_hare_mock.rb', line 107

def publish(msg, msg_attrs = {})
  queues.each { |q| q.messages << msg }
end