class Stockpile::Memory

An in-memory connection manager, providing a complete example of how a Stockpile connection manager could be made.

Attributes

connection[R]

The primary connection.

Public Class Methods

new(options = {}) click to toggle source

Create a new Memory connection manager.

# File lib/stockpile/memory.rb, line 82
    

Public Instance Methods

connect(*client_names) click to toggle source

Connect unless already connected. Additional client connections can be specified in the parameters as a shorthand for calls to connection_for.

If narrow? is true, the same connection will be used for all clients managed by this connection manager.

manager.connect
manager.connection_for(:bar)

# This means the same as above.
manager.connect(:bar)
# File lib/stockpile/memory.rb, line 99
    
connection_for(client_name, options = {}) click to toggle source

Perform a client connection for a specific client_name. A client_name of :all will always return nil. If the requested client does not yet exist, the connection will be created.

# File lib/stockpile/memory.rb, line 116
    
disconnect(*client_names) click to toggle source

Disconnect for some or all clients. The primary connection will always be disconnected; other clients will be disconnected based on the clients provided. Only clients actively managed by previous calls to connect or connection_for will be disconnected.

If disconnect is called with the value :all, all currently managed clients will be disconnected.

If narrow? is true, the primary connection will be disconnected, which disconnects all connections implicitly.

# File lib/stockpile/memory.rb, line 141
    
narrow?() click to toggle source

Indicates if this connection manager is using a narrow connection width.

# File lib/stockpile/memory.rb, line 94
    
reconnect(*client_names) click to toggle source

Reconnect some or all clients. The primary connection will always be reconnected; other clients will be reconnected based on the clients provided. Only clients actively managed by previous calls to connect or connection_for will be reconnected.

If reconnect is called with the value :all, all currently managed clients will be reconnected.

If narrow? is true, the primary connection will be reconnected, which reconnects all connections implicitly.

# File lib/stockpile/memory.rb, line 125
    

Private Instance Methods

client_connect(_name = nil, options = {}) click to toggle source
# File lib/stockpile/memory.rb, line 160
def client_connect(_name = nil, options = {})
  return connection if connection && narrow?
  Data.new(@options.merge(options))
end
client_disconnect(client = connection) click to toggle source
# File lib/stockpile/memory.rb, line 169
def client_disconnect(client = connection)
  client.disconnect if client
end
client_reconnect(client = connection) click to toggle source
# File lib/stockpile/memory.rb, line 165
def client_reconnect(client = connection)
  client.reconnect if client
end