module Purview::Mixins::Connection

Public Instance Methods

connect() click to toggle source
# File lib/purview/mixins/connection.rb, line 4
def connect
  connection_type.connect(connection_opts)
end
connection_opts() click to toggle source
# File lib/purview/mixins/connection.rb, line 8
def connection_opts
  {
    :database => database_name,
    :host => database_host,
    :password => database_password,
    :port => database_port,
    :username => database_username,
  }
end
with_new_connection() { |connection = connect| ... } click to toggle source
# File lib/purview/mixins/connection.rb, line 18
def with_new_connection
  yield connection = connect
ensure
  connection.disconnect if connection
end
with_new_or_existing_connection(opts={}) { |existing_connection| ... } click to toggle source
# File lib/purview/mixins/connection.rb, line 24
def with_new_or_existing_connection(opts={})
  if existing_connection = opts[:connection]
    yield existing_connection
  else
    with_new_connection { |connection| yield connection }
  end
end
with_transaction(connection) { || ... } click to toggle source
# File lib/purview/mixins/connection.rb, line 32
def with_transaction(connection)
  connection.with_transaction { yield }
end