Where is database.yml loaded in ActiveRecord in Rails 4?

What line (or method) in the ActiveRecord code base does config / database.yml load for the Rails application? (I look at 4.0.5 specifically, but if someone has information about> = 4.0.5, this will cover)?

+3
source share
2 answers

It is inside the rails, in particular, in the file railties/lib/rails/application/configuration.rbon lines 101-116 (for Rails 4.0.6):

https://github.com/rails/rails/blob/4-0-6/railties/lib/rails/application/configuration.rb#L101-L116

# Loads and returns the configuration of the database.
def database_configuration
  yaml = paths["config/database"].first
  if File.exist?(yaml)
    require "erb"
    YAML.load ERB.new(IO.read(yaml)).result
  elsif ENV['DATABASE_URL']
    nil
  else
    raise "Could not load database configuration. No such file - #{yaml}"
  end
rescue Psych::SyntaxError => e
  raise "YAML syntax error occurred while parsing #{paths["config/database"].first}. " \
        "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
        "Error: #{e.message}"
end
+6
source

Rails 4.0.6 "database.yml" -File :

paths.add "config/database",    with: "config/database.yml"

( ) :

YAML.load ERB.new(IO.read(yaml)).result
+1

Source: https://habr.com/ru/post/1673167/


All Articles