In this chapter, I’ll discuss the adapter initialization; how Rails 2.x reads from database.yml and launches the database initialization.
Here is a condensation of the Rails boot process from Rails Guts. As Mike Gunderloy suggests, it will be really helpful to have a blank rails app open with
rake gems:freeze
invoked :
Rails::Initializer.run do |config|
configuration = Configuration.new
(that’s Rails::Configuration in railties/lib/initializer.rb)
self.database_configuration_file = default_database_configuration_file
def default_database_configuration_file File.join(root_path, 'config', 'database.yml') end
def initialize_database if configuration.frameworks.include?(:active_record) ActiveRecord::Base.configurations = configuration.database_configuration ActiveRecord::Base.establish_connection end end
def database_configuration require 'erb' YAML::load(ERB.new(IO.read(database_configuration_file)).result) end
gem "activerecord-#{spec[:adapter]}-adapter"
and execute the adapter-method (which is expected to be def’d from the adapter’s gem) :
adapter_method = "#{spec[:adapter]}_connection"
The adapter-method is the entry-point of our new adapter, so in my next post I’ll pick-apart the #establish_connection process and prepare for our multi-connection pooling adapter’s version.