Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added configurable eager load paths. Defaults to app/models, app/cont…

…rollers, and app/helpers
  • Loading branch information...
commit 89ec72c2818a592323fe4ec3277638d379f1ac2a 1 parent 3bd34b6
@josh josh authored
Showing with 23 additions and 4 deletions.
  1. +2 −0  railties/CHANGELOG
  2. +21 −4 railties/lib/initializer.rb
View
2  railties/CHANGELOG
@@ -1,5 +1,7 @@
*Edge*
+* Added configurable eager load paths. Defaults to app/models, app/controllers, and app/helpers [Josh Peek]
+
* Introduce simple internationalization support. [Ruby i18n team]
* Make script/plugin install <plugin> -r <revision> option work with git based plugins. #257. [Tim Pope Jakub Kuźma]. Example:
View
25 railties/lib/initializer.rb
@@ -333,11 +333,14 @@ def load_observers
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 @@ class Configuration
# 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 @@ def initialize
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 @@ def default_load_once_paths
[]
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
Please sign in to comment.
Something went wrong with that request. Please try again.