Non*_*ona 4 ruby activerecord ruby-on-rails-4 rails-activerecord
ActiveRecord代码库中的哪一行(或方法)是否加载了Rails应用程序的config/database.yml?(我正在特别关注4.0.5,但如果有人有关于= = 4.0.5的任何信息,那将是有启发性的)?
Pat*_*ity 10
它位于Railties内部,特别是railties/lib/rails/application/configuration.rb在第101-116行的文件中(对于Rails 4.0.5):
https://github.com/rails/rails/blob/v4.0.5/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
Run Code Online (Sandbox Code Playgroud)