Class: BunnyMock::Queue
- Inherits:
-
Object
- Object
- BunnyMock::Queue
- Defined in:
- lib/bunny_mock.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#delivery_count ⇒ Object
Returns the value of attribute delivery_count.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #bind(exchange) ⇒ Object
- #default_consumer ⇒ Object
-
#initialize(name, attrs = {}) ⇒ Queue
constructor
A new instance of Queue.
- #method_missing(method, *args) ⇒ Object
- #publish(msg) ⇒ Object
-
#snapshot_messages ⇒ Object
NOTE: This is NOT a method that is supported on real Bunny queues.
-
#subscribe(*args, &block) ⇒ Object
Note that this doesn’t block waiting for messages like the real world.
Constructor Details
#initialize(name, attrs = {}) ⇒ Queue
Returns a new instance of Queue.
52 53 54 55 56 57 |
# File 'lib/bunny_mock.rb', line 52 def initialize(name, attrs = {}) self.name = name self.attrs = attrs.dup self. = [] self.delivery_count = 0 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/bunny_mock.rb', line 89 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.
51 52 53 |
# File 'lib/bunny_mock.rb', line 51 def attrs @attrs end |
#delivery_count ⇒ Object
Returns the value of attribute delivery_count.
51 52 53 |
# File 'lib/bunny_mock.rb', line 51 def delivery_count @delivery_count end |
#messages ⇒ Object
Returns the value of attribute messages.
51 52 53 |
# File 'lib/bunny_mock.rb', line 51 def end |
#name ⇒ Object
Returns the value of attribute name.
51 52 53 |
# File 'lib/bunny_mock.rb', line 51 def name @name end |
Instance Method Details
#bind(exchange) ⇒ Object
59 60 61 |
# File 'lib/bunny_mock.rb', line 59 def bind(exchange) exchange.queues << self end |
#default_consumer ⇒ Object
75 76 77 |
# File 'lib/bunny_mock.rb', line 75 def default_consumer BunnyMock::Consumer.new(self.delivery_count) end |
#publish(msg) ⇒ Object
71 72 73 |
# File 'lib/bunny_mock.rb', line 71 def publish(msg) self. << msg end |
#snapshot_messages ⇒ Object
NOTE: This is NOT a method that is supported on real Bunny queues.
This is a custom method to get us a deep copy of
all the currently in the queue. This is provided
to aid in testing a system where it is not practical for the
test to subscribe to the queue and read the , but we
need to verify that certain have been published.
85 86 87 |
# File 'lib/bunny_mock.rb', line 85 def Marshal.load(Marshal.dump()) end |
#subscribe(*args, &block) ⇒ Object
Note that this doesn’t block waiting for messages like the real world.
64 65 66 67 68 69 |
# File 'lib/bunny_mock.rb', line 64 def subscribe(*args, &block) while = .shift self.delivery_count += 1 yield({:payload => }) end end |