aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/initializer.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-07-21 13:42:34 -0500
committerJoshua Peek <josh@joshpeek.com>2008-07-21 13:43:23 -0500
commit89ec72c2818a592323fe4ec3277638d379f1ac2a (patch)
tree6e6d07491eafc3a9ab6ee06b1fe0913748693048 /railties/lib/initializer.rb
parent3bd34b6ffe017dd81fd26743aab052fc4324eb0f (diff)
downloadrails-89ec72c2818a592323fe4ec3277638d379f1ac2a.tar.gz
rails-89ec72c2818a592323fe4ec3277638d379f1ac2a.tar.bz2
rails-89ec72c2818a592323fe4ec3277638d379f1ac2a.zip
Added configurable eager load paths. Defaults to app/models, app/controllers, and app/helpers
Diffstat (limited to 'railties/lib/initializer.rb')
-rw-r--r--railties/lib/initializer.rb25
1 files changed, 21 insertions, 4 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 3be95de8d3..828d688475 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -333,11 +333,14 @@ Run `rake gems:install` to install the missing gems.
end
end
+ # Eager load application classes
def load_application_classes
- require_dependency 'application'
-
- Dir.glob('app/{models,controllers,helpers}/*.rb').each do |file|
- require_dependency file
+ if configuration.cache_classes
+ configuration.eager_load_paths.each do |load_path|
+ Dir.glob("#{load_path}/*.rb").each do |file|
+ require_dependency file
+ end
+ end
end
end
@@ -578,6 +581,11 @@ Run `rake gems:install` to install the missing gems.
# All elements of this array must also be in +load_paths+.
attr_accessor :load_once_paths
+ # An array of paths from which Rails will eager load on boot if cache
+ # classes is enabled. All elements of this array must also be in
+ # +load_paths+.
+ attr_accessor :eager_load_paths
+
# The log level to use for the default Rails logger. In production mode,
# this defaults to <tt>:info</tt>. In development mode, it defaults to
# <tt>:debug</tt>.
@@ -686,6 +694,7 @@ Run `rake gems:install` to install the missing gems.
self.frameworks = default_frameworks
self.load_paths = default_load_paths
self.load_once_paths = default_load_once_paths
+ self.eager_load_paths = default_eager_load_paths
self.log_path = default_log_path
self.log_level = default_log_level
self.view_path = default_view_path
@@ -826,6 +835,14 @@ Run `rake gems:install` to install the missing gems.
[]
end
+ def default_eager_load_paths
+ %w(
+ app/models
+ app/controllers
+ app/helpers
+ ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
+ end
+
def default_log_path
File.join(root_path, 'log', "#{environment}.log")
end