Class: S3Light::ConnectionsManager::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/s3-light/connections_manager/main.rb

Instance Method Summary collapse

Constructor Details

#initializeMain

Returns a new instance of Main.



6
7
8
# File 'lib/s3-light/connections_manager/main.rb', line 6

def initialize
  @connections = {}
end

Instance Method Details

#close_all_connectionsObject



25
26
27
28
29
30
31
32
# File 'lib/s3-light/connections_manager/main.rb', line 25

def close_all_connections
  return if @connections.empty?
  @connections.each do |_, connection|
    connection.close
  end

  @connections = {}
end

#yield_connection(client, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/s3-light/connections_manager/main.rb', line 10

def yield_connection(client, &block)
  client_connection = nil
  @connections.each do |existing_client, connection|
    if client.endpoint == existing_client.endpoint
      client_connection = connection
      break
    end
  end

  client_connection ||= create_new_connection(client)
  @connections[client] = client_connection

  block.call(client_connection)
end