Class: BunnyMock::Exchange
- Inherits:
-
Object
- Object
- BunnyMock::Exchange
- Defined in:
- lib/support/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.
86 87 88 89 90 |
# File 'lib/support/bunny_mock.rb', line 86 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
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/support/bunny_mock.rb', line 100 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.
85 86 87 |
# File 'lib/support/bunny_mock.rb', line 85 def attrs @attrs end |
#name ⇒ Object
Returns the value of attribute name.
85 86 87 |
# File 'lib/support/bunny_mock.rb', line 85 def name @name end |
#queues ⇒ Object
Returns the value of attribute queues.
85 86 87 |
# File 'lib/support/bunny_mock.rb', line 85 def queues @queues end |
Instance Method Details
#bound_to?(queue_name) ⇒ Boolean
96 97 98 |
# File 'lib/support/bunny_mock.rb', line 96 def bound_to?(queue_name) queues.any?{|q| q.name == queue_name} end |
#publish(msg, msg_attrs = {}) ⇒ Object
92 93 94 |
# File 'lib/support/bunny_mock.rb', line 92 def publish(msg, msg_attrs = {}) queues.each { |q| q. << msg } end |