Class: BunnyMock::Exchange
- Inherits:
-
Object
- Object
- BunnyMock::Exchange
- Defined in:
- lib/bunny_mock.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#name ⇒ Object
Returns the value of attribute name.
-
#queues ⇒ Object
Returns the value of attribute queues.
Instance Method Summary collapse
- #bound_to?(queue_name) ⇒ Boolean
-
#initialize(name, attrs = {}) ⇒ Exchange
constructor
A new instance of Exchange.
- #method_missing(method, *args) ⇒ Object
- #publish(msg, msg_attrs = {}) ⇒ Object
Constructor Details
#initialize(name, attrs = {}) ⇒ Exchange
Returns a new instance of Exchange.
110 111 112 113 114 |
# File 'lib/bunny_mock.rb', line 110 def initialize(name, 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
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/bunny_mock.rb', line 124 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
#attrs ⇒ Object
Returns the value of attribute attrs.
109 110 111 |
# File 'lib/bunny_mock.rb', line 109 def attrs @attrs end |
#name ⇒ Object
Returns the value of attribute name.
109 110 111 |
# File 'lib/bunny_mock.rb', line 109 def name @name end |
#queues ⇒ Object
Returns the value of attribute queues.
109 110 111 |
# File 'lib/bunny_mock.rb', line 109 def queues @queues end |
Instance Method Details
#bound_to?(queue_name) ⇒ Boolean
120 121 122 |
# File 'lib/bunny_mock.rb', line 120 def bound_to?(queue_name) queues.any?{|q| q.name == queue_name} end |
#publish(msg, msg_attrs = {}) ⇒ Object
116 117 118 |
# File 'lib/bunny_mock.rb', line 116 def publish(msg, msg_attrs = {}) queues.each { |q| q. << msg } end |