Class: EzPool::ConnectionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/ezpool/connection_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(connect_with, disconnect_with = nil) ⇒ ConnectionManager

Returns a new instance of ConnectionManager.



6
7
8
9
# File 'lib/ezpool/connection_manager.rb', line 6

def initialize(connect_with, disconnect_with = nil)
  @connect_with = connect_with
  @disconnect_with = disconnect_with
end

Instance Method Details

#connectObject



11
12
13
14
15
16
# File 'lib/ezpool/connection_manager.rb', line 11

def connect
  if @connect_with.nil?
    raise EzPool::ConnectCallableNeverConfigured.new()
  end
  @connect_with.call
end

#connect_with(&block) ⇒ Object



24
25
26
# File 'lib/ezpool/connection_manager.rb', line 24

def connect_with(&block)
  @connect_with = block
end

#create_newObject

Create a new wrapped connection



34
35
36
# File 'lib/ezpool/connection_manager.rb', line 34

def create_new
  EzPool::ConnectionWrapper.new(connect, self)
end

#disconnect(conn) ⇒ Object



18
19
20
21
22
# File 'lib/ezpool/connection_manager.rb', line 18

def disconnect(conn)
  if !@disconnect_with.nil?
    @disconnect_with.call(conn)
  end
end

#disconnect_with(&block) ⇒ Object



28
29
30
# File 'lib/ezpool/connection_manager.rb', line 28

def disconnect_with(&block)
  @disconnect_with = block
end