class BunnyMock::Session
Mocks Bunny::Session
Attributes
@return [Hash<String, BunnyMock::Exchange>] Exchanges
created by this channel
@return [Hash<String, BunnyMock::Queue>] Queues created by this channel
@return [Symbol] Current session status
Public Class Methods
Creates a new {BunnyMock::Session} instance
@api public
# File lib/bunny_mock/session.rb, line 22 def initialize(*) # not connected until {BunnyMock::Session#start} is called @status = :not_connected # create channel hash @channels = {} # create storage for queues and exchanges @queues = {} @exchanges = {} end
Public Instance Methods
Tests if connection is closed
@return [Boolean] true if status is closed, false otherwise @api public
# File lib/bunny_mock/session.rb, line 70 def closed? @status == :closed end
Tests if connection is closing
@return [Boolean] true if status is closing, false otherwise @api public
# File lib/bunny_mock/session.rb, line 79 def closing? @status == :closing end
Creates a new {BunnyMock::Channel} instance
@param [Integer] n Channel
identifier @param [Integer] pool_size Work pool size (insignificant)
@return [BunnyMock::Channel] Channel
instance @api public
# File lib/bunny_mock/session.rb, line 91 def create_channel(n = nil, _pool_size = 1, *_args) # raise same error as {Bunny::Session#create_channel} raise ArgumentError, 'channel number 0 is reserved in the protocol and cannot be used' if n && n.zero? # return cached channel if exists return @channels[n] if n && @channels.key?(n) # create and open channel channel = Channel.new self, n channel.open # return channel @channels[n] = channel end
@private
# File lib/bunny_mock/session.rb, line 180 def deregister_exchange(xchg) @exchanges.delete xchg end
@private
# File lib/bunny_mock/session.rb, line 165 def deregister_queue(queue) @queues.delete queue end
Test if exchange exists in channel cache
@param [String] name Name of exchange
@return [Boolean] true if exchange exists, false otherwise @api public
# File lib/bunny_mock/session.rb, line 146 def exchange_exists?(name) !find_exchange(name).nil? end
@private
# File lib/bunny_mock/session.rb, line 170 def find_exchange(name) @exchanges[name] end
@private
# File lib/bunny_mock/session.rb, line 155 def find_queue(name) @queues[name] end
Tests if connection is available
@return [Boolean] true if status is connected, false otherwise @api public
# File lib/bunny_mock/session.rb, line 60 def open? @status == :connected end
Test if queue exists in channel cache
@param [String] name Name of queue
@return [Boolean] true if queue exists, false otherwise @api public
# File lib/bunny_mock/session.rb, line 134 def queue_exists?(name) !find_queue(name).nil? end
@private
# File lib/bunny_mock/session.rb, line 175 def register_exchange(xchg) @exchanges[xchg.name] = xchg end
@private
# File lib/bunny_mock/session.rb, line 160 def register_queue(queue) @queues[queue.name] = queue end
Sets status to connected
@return [BunnyMock::Session] self @api public
# File lib/bunny_mock/session.rb, line 39 def start @status = :connected self end
Sets status to closed
@return [BunnyMock::Session] self @api public
# File lib/bunny_mock/session.rb, line 49 def stop @status = :closed self end
Creates a temporary {BunnyMock::Channel} instance, yields it to the block given, then closes it
@param [Integer] n Channel
identifier
@return [BunnyMock::Session] self @api public
# File lib/bunny_mock/session.rb, line 115 def with_channel(n = nil) ch = create_channel(n) begin yield ch ensure ch.close if ch.open? end self end