def load_environment
silence_warnings do
return if @environment_loaded
@environment_loaded = true
config = configuration
constants = self.class.constants
eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
(self.class.constants - constants).each do |const|
Object.const_set(const, self.class.const_get(const))
end
end
end
Configuration.environment_path を eval しています。Configuration.environment_path は
def environment_path
"#{root_path}/config/environments/#{environment}.rb"
end
def environment
::RAILS_ENV
end
なので、config/envirionments 以下の、RAILS_ENV で指定された実行モード設定ファイル(デフォルトはdevelopment.rb)を読み込むことになります。
[Rails][CodeReading] Railsの初期化コードを読む (イントロ&目次)
0 件のコメント:
コメントを投稿