# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 150 def clear_active_connections! connection_handler.clear_active_connections! end
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
Returns true if Keymap is connected.
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 142 def connected? connection_handler.connected?(self) end
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
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
The connection handler
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 88 class_attribute :connection_handler, :instance_writer => false
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 115 def connection_id Thread.current['Keymap::Base.connection_id'] end
# 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
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 133 def connection_pool connection_handler.retrieve_connection_pool(self) or raise ConnectionNotEstablished end
# 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
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
# File lib/keymap/base.rb, line 47 def initialize(attributes = nil, options = {}) yield self if block_given? #run_callbacks :initialize end
# 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
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 146 def remove_connection(klass = self) connection_handler.remove_connection(klass) end
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 137 def retrieve_connection connection_handler.retrieve_connection(self) end
# File lib/keymap/connection_adapters/abstract/connection_specification.rb, line 91 def connection self.class.connection end