lib/bunny_mock/session.rb in bunny-mock-1.0.0 vs lib/bunny_mock/session.rb in bunny-mock-1.1.0
- old
+ new
@@ -7,10 +7,16 @@
#
# @return [Symbol] Current session status
attr_reader :status
+ # @return [Hash<String, BunnyMock::Exchange>] Exchanges created by this channel
+ attr_reader :exchanges
+
+ # @return [Hash<String, BunnyMock::Queue>] Queues created by this channel
+ attr_reader :queues
+
##
# Creates a new {BunnyMock::Session} instance
#
# @api public
def initialize(*args)
@@ -18,10 +24,14 @@
# not connected until {BunnyMock::Session#start} is called
@status = :not_connected
# create channel hash
@channels = Hash.new
+
+ # create storage for queues and exchanges
+ @queues = Hash.new
+ @exchanges = Hash.new
end
##
# Sets status to connected
#
@@ -79,7 +89,65 @@
# return channel
@channels[n] = channel
end
alias channel create_channel
+
+ ##
+ # Test if queue exists in channel cache
+ #
+ # @param [String] name Name of queue
+ #
+ # @return [Boolean] true if queue exists, false otherwise
+ # @api public
+ #
+ def queue_exists?(name)
+ !!find_queue(name)
+ end
+
+ ##
+ # Test if exchange exists in channel cache
+ #
+ # @param [String] name Name of exchange
+ #
+ # @return [Boolean] true if exchange exists, false otherwise
+ # @api public
+ #
+ def exchange_exists?(name)
+ !!find_exchange(name)
+ end
+
+ #
+ # Implementation
+ #
+
+ # @private
+ def find_queue(name)
+ @queues[name]
+ end
+
+ # @private
+ def register_queue(queue)
+ @queues[queue.name] = queue
+ end
+
+ # @private
+ def deregister_queue(queue)
+ @queues.delete queue
+ end
+
+ # @private
+ def find_exchange(name)
+ @exchanges[name]
+ end
+
+ # @private
+ def register_exchange(xchg)
+ @exchanges[xchg.name] = xchg
+ end
+
+ # @private
+ def deregister_exchange(xchg)
+ @exchanges.delete xchg
+ end
end
end