Class: BunnyMock::Session
- Inherits:
-
Object
- Object
- BunnyMock::Session
- Defined in:
- lib/bunny_mock/session.rb
Overview
Mocks Bunny::Session
Instance Attribute Summary collapse
-
#exchanges ⇒ Hash<String, BunnyMock::Exchange>
readonly
Exchanges created by this channel.
-
#queues ⇒ Hash<String, BunnyMock::Queue>
readonly
Queues created by this channel.
-
#status ⇒ Symbol
readonly
Current session status.
Instance Method Summary collapse
-
#closed? ⇒ Boolean
Tests if connection is closed.
-
#closing? ⇒ Boolean
Tests if connection is closing.
-
#create_channel(n = nil, _pool_size = 1, *_args) ⇒ BunnyMock::Channel
(also: #channel)
Creates a new Channel instance.
-
#exchange_exists?(name) ⇒ Boolean
Test if exchange exists in channel cache.
-
#initialize ⇒ Session
constructor
Creates a new Session instance.
-
#open? ⇒ Boolean
(also: #connected?)
Tests if connection is available.
-
#queue_exists?(name) ⇒ Boolean
Test if queue exists in channel cache.
-
#start ⇒ BunnyMock::Session
Sets status to connected.
-
#stop ⇒ BunnyMock::Session
(also: #close)
Sets status to closed.
-
#with_channel(n = nil) ⇒ BunnyMock::Session
Creates a temporary Channel instance, yields it to the block given, then closes it.
Constructor Details
#initialize ⇒ Session
Creates a new BunnyMock::Session instance
22 23 24 25 26 27 28 29 30 31 32 |
# 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 |
Instance Attribute Details
#exchanges ⇒ Hash<String, BunnyMock::Exchange> (readonly)
Returns Exchanges created by this channel.
13 14 15 |
# File 'lib/bunny_mock/session.rb', line 13 def exchanges @exchanges end |
#queues ⇒ Hash<String, BunnyMock::Queue> (readonly)
Returns Queues created by this channel.
16 17 18 |
# File 'lib/bunny_mock/session.rb', line 16 def queues @queues end |
#status ⇒ Symbol (readonly)
Returns Current session status.
10 11 12 |
# File 'lib/bunny_mock/session.rb', line 10 def status @status end |
Instance Method Details
#closed? ⇒ Boolean
Tests if connection is closed
70 71 72 |
# File 'lib/bunny_mock/session.rb', line 70 def closed? @status == :closed end |
#closing? ⇒ Boolean
Tests if connection is closing
79 80 81 |
# File 'lib/bunny_mock/session.rb', line 79 def closing? @status == :closing end |
#create_channel(n = nil, _pool_size = 1, *_args) ⇒ BunnyMock::Channel Also known as: channel
Creates a new Channel instance
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# 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 |
#exchange_exists?(name) ⇒ Boolean
Test if exchange exists in channel cache
146 147 148 |
# File 'lib/bunny_mock/session.rb', line 146 def exchange_exists?(name) !find_exchange(name).nil? end |
#open? ⇒ Boolean Also known as: connected?
Tests if connection is available
60 61 62 |
# File 'lib/bunny_mock/session.rb', line 60 def open? @status == :connected end |
#queue_exists?(name) ⇒ Boolean
Test if queue exists in channel cache
134 135 136 |
# File 'lib/bunny_mock/session.rb', line 134 def queue_exists?(name) !find_queue(name).nil? end |
#start ⇒ BunnyMock::Session
Sets status to connected
39 40 41 42 |
# File 'lib/bunny_mock/session.rb', line 39 def start @status = :connected self end |
#stop ⇒ BunnyMock::Session Also known as: close
Sets status to closed
49 50 51 52 |
# File 'lib/bunny_mock/session.rb', line 49 def stop @status = :closed self end |
#with_channel(n = nil) ⇒ BunnyMock::Session
Creates a temporary Channel instance, yields it to the block given, then closes it
115 116 117 118 119 120 121 122 123 124 |
# 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 |