def load_application_classes
return if $rails_rake_task
if configuration.cache_classes
configuration.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
require_dependency file.sub(matcher, '\1')
end
end
end
end
これはわかりやすい。
Configuration.cache_classes が true なら、Configuration.eager_load_paths 以下の .rb ファイルを require_dependency します。
Configuration.cache_classes のデフォルト値は true。
def default_cache_classes
true
end
Configuration.eager_load_paths にはデフォルトで以下が含まれます。
def default_eager_load_paths
%w(
app/metal
app/models
app/controllers
app/helpers
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
end
require_dependency に関しては、こちらが参考になります。
[Rails][CodeReading] Railsの初期化コードを読む (イントロ&目次)
0 件のコメント:
コメントを投稿