Module: ActiveRecord::ConnectionAdapters
Constant Summary
-
PostgreSQLColumn =
Internal use only
# File 'activerecord/lib/active_record/connection_adapters/postgresql/column.rb', line 80PostgreSQL::Column
-
PostgreSQLTypeMetadata =
Internal use only
# File 'activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb', line 42PostgreSQL::TypeMetadata
Class Method Summary
-
.register(name, class_name, path = class_name.underscore)
Registers a custom database adapter.
- .resolve(adapter_name) Internal use only
::ActiveSupport::Autoload
- Extended
Class Method Details
.register(name, class_name, path = class_name.underscore)
Registers a custom database adapter.
Can also be used to define aliases.
Example
ActiveRecord::ConnectionAdapters.register("megadb", "MegaDB::ActiveRecordAdapter", "mega_db/active_record_adapter")
ActiveRecord::ConnectionAdapters.register("mysql", "ActiveRecord::ConnectionAdapters::TrilogyAdapter", "active_record/connection_adapters/trilogy_adapter")
# File 'activerecord/lib/active_record/connection_adapters.rb', line 22
def register(name, class_name, path = class_name.underscore) @adapters[name.to_s] = [class_name, path] end
.resolve(adapter_name)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters.rb', line 26
def resolve(adapter_name) # :nodoc: # Require the adapter itself and give useful feedback about # 1. Missing adapter gems. # 2. Incorrectly registered adapters. # 3. Adapter gems' missing dependencies. class_name, path_to_adapter = @adapters[adapter_name.to_s] unless class_name raise AdapterNotFound, <<~MSG.squish Database configuration specifies nonexistent '#{adapter_name}' adapter. Available adapters are: #{@adapters.keys.sort.join(", ")}. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile if it's not in the list of available adapters. MSG end unless Object.const_defined?(class_name) begin require path_to_adapter rescue LoadError => error # We couldn't require the adapter itself. if error.path == path_to_adapter # We can assume here that a non-builtin adapter was specified and the path # registered by the adapter gem is incorrect. raise LoadError, "Error loading the '#{adapter_name}' Active Record adapter. Ensure that the path registered by the adapter gem is correct. #{error.}", error.backtrace else # Bubbled up from the adapter require. Prefix the exception message # with some guidance about how to address it and reraise. raise LoadError, "Error loading the '#{adapter_name}' Active Record adapter. Missing a gem it depends on? #{error.}", error.backtrace end end end begin Object.const_get(class_name) rescue NameError => error raise AdapterNotFound, "Could not load the #{class_name} Active Record adapter (#{error.})." end end