module Sequel::ArbitraryServers

Private Instance Methods

acquire(thread, server) click to toggle source

If server is a hash, create a new connection for it, and cache it first by thread and then server.

Calls superclass method
# File lib/sequel/extensions/arbitrary_servers.rb, line 63
def acquire(thread, server)
  if server.is_a?(Hash)
    sync{@allocated[thread] ||= {}}[server] = make_new(server)
  else
    super
  end
end
owned_connection(thread, server) click to toggle source

If server is a hash, the entry for it probably doesn't exist in the @allocated hash, so check for existence to avoid calling nil.[]

Calls superclass method
# File lib/sequel/extensions/arbitrary_servers.rb, line 74
def owned_connection(thread, server)
  if server.is_a?(Hash)
    if a = sync{@allocated[thread]}
      a[server]
    end
  else
    super
  end
end
pick_server(server) click to toggle source

If server is a hash, return it directly.

Calls superclass method
# File lib/sequel/extensions/arbitrary_servers.rb, line 85
def pick_server(server)
  if server.is_a?(Hash)
    server
  else
    super
  end
end
release(thread, conn, server) click to toggle source

If server is a hash, delete the thread from the allocated connections for that server. Additionally, if this was the last thread using that server, delete the server from the @allocated hash.

Calls superclass method
# File lib/sequel/extensions/arbitrary_servers.rb, line 96
def release(thread, conn, server)
  if server.is_a?(Hash)
    a = @allocated[thread]
    a.delete(server)
    @allocated.delete(thread) if a.empty?
    db.disconnect_connection(conn)
  else  
    super
  end
end