class Keymap::Base

Public Class Methods

clear_active_connections!() click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 150
def clear_active_connections!
  connection_handler.clear_active_connections!
end
configurations() click to toggle source

Contains the database configuration - as is typically stored in config/database.yml - as a Hash.

For example, the following database.yml…

development:
  adapter: redis

production:
  adapter: redis

…would result in ::configurations to look like this:

{
   'development' => {
      'adapter'  => 'redis',
   },
   'production' => {
      'adapter'  => 'redis',
   }
}
# File lib/keymap/base.rb, line 42
cattr_accessor :configurations, :instance_writer => false
connected?() click to toggle source

Returns true if Keymap is connected.

# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 142
def connected?
  connection_handler.connected?(self)
end
connection() click to toggle source

Returns the connection currently associated with the class. This can also be used to “borrow” the connection to do database work unrelated to any of the specific Keymap collections.

# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 111
def connection
  retrieve_connection
end
connection_config() click to toggle source

Returns the configuration of the associated connection as a hash:

Keymap::Base.connection_config
# => {:pool=>5, :timeout=>5000, :adapter=>"redis"}

Please use only for reading.

# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 129
def connection_config
  connection_pool.spec.config
end
connection_handler() click to toggle source

The connection handler

# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 88
class_attribute :connection_handler, :instance_writer => false
connection_id() click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 115
def connection_id
  Thread.current['Keymap::Base.connection_id']
end
connection_id=(connection_id) click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 119
def connection_id=(connection_id)
  Thread.current['Keymap::Base.connection_id'] = connection_id
end
connection_pool() click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 133
def connection_pool
  connection_handler.retrieve_connection_pool(self) or raise ConnectionNotEstablished
end
establish_connection(spec = ENV["DATABASE_URL"]) click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 95
def self.establish_connection(spec = ENV["DATABASE_URL"])
  resolver = Keymap::Base::ConnectionSpecification::Resolver.new spec, configurations
  spec = resolver.spec

  unless respond_to?(spec.adapter_method)
    raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
  end

  remove_connection
  connection_handler.establish_connection name, spec
end
logger() click to toggle source

Accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then passed on to any new database connections made and which can be retrieved on both a class and instance level by calling logger.

# File lib/keymap/base.rb, line 17
cattr_accessor :logger, :instance_writer => false
new(attributes = nil, options = {}) { |self| ... } click to toggle source
# File lib/keymap/base.rb, line 47
def initialize(attributes = nil, options = {})
  yield self if block_given?
  #run_callbacks :initialize
end
redis_connection(config) click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 7
def self.redis_connection(config)
  config = config.symbolize_keys
  config[:port] ||= 6379
  ConnectionAdapters::RedisAdapter.new(nil, nil, config)
end
remove_connection(klass = self) click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 146
def remove_connection(klass = self)
  connection_handler.remove_connection(klass)
end
retrieve_connection() click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 137
def retrieve_connection
  connection_handler.retrieve_connection(self)
end

Public Instance Methods

connection() click to toggle source
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 91
def connection
  self.class.connection
end