aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/paths.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-28 00:57:47 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-28 01:22:32 +0200
commit9b19a6f16cebf4257d2f0b839f6cc8ff5db5c47b (patch)
tree98028044107a83c44f658e077a587c65d27d31b3 /railties/lib/rails/paths.rb
parent4329f8133fee8e4f3e558787f67de59f0c4a4dd1 (diff)
downloadrails-9b19a6f16cebf4257d2f0b839f6cc8ff5db5c47b.tar.gz
rails-9b19a6f16cebf4257d2f0b839f6cc8ff5db5c47b.tar.bz2
rails-9b19a6f16cebf4257d2f0b839f6cc8ff5db5c47b.zip
A few changes were done in this commit:
* Added :autoload to engines path API and redefine usage to be in sync with 6f83a5036d8a9c3f8ed7; * Do not autoload code in *lib* for applications (now you need to explicitly require them). This makes an application behave closer to an engine (code in lib is still autoloaded for plugins); * Always autoload code in app/ for engines and plugins. This makes engines behave closer to an application and should allow us to get rid of the unloadable hack required when controllers inside engines inherit from ApplicationController;
Diffstat (limited to 'railties/lib/rails/paths.rb')
-rw-r--r--railties/lib/rails/paths.rb51
1 files changed, 31 insertions, 20 deletions
diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb
index 1c9e308631..7a65188a9a 100644
--- a/railties/lib/rails/paths.rb
+++ b/railties/lib/rails/paths.rb
@@ -25,9 +25,7 @@ module Rails
def initialize(path)
raise if path.is_a?(Array)
-
@children = {}
-
@path = path
@root = self
@all_paths = []
@@ -38,14 +36,18 @@ module Rails
@all_paths
end
- def load_once
- filter_by(:load_once?)
+ def autoload_once
+ filter_by(:autoload_once?)
end
def eager_load
filter_by(:eager_load?)
end
+ def autoload_paths
+ filter_by(:autoload?)
+ end
+
def load_paths
filter_by(:load_path?)
end
@@ -61,15 +63,17 @@ module Rails
protected
def filter_by(constraint)
- all_paths.map do |path|
+ all = []
+ all_paths.each do |path|
if path.send(constraint)
paths = path.paths
paths -= path.children.values.map { |p| p.send(constraint) ? [] : p.paths }.flatten
- paths
- else
- []
+ all.concat(paths)
end
- end.flatten.uniq.select { |p| File.exists?(p) }
+ end
+ all.uniq!
+ all.reject! { |p| !File.exists?(p) }
+ all
end
end
@@ -80,15 +84,16 @@ module Rails
attr_accessor :glob
def initialize(root, *paths)
- @options = paths.last.is_a?(::Hash) ? paths.pop : {}
+ options = paths.last.is_a?(::Hash) ? paths.pop : {}
@children = {}
@root = root
@paths = paths.flatten
- @glob = @options.delete(:glob)
+ @glob = options[:glob]
- @load_once = @options[:load_once]
- @eager_load = @options[:eager_load]
- @load_path = @options[:load_path] || @eager_load || @load_once
+ autoload_once! if options[:autoload_once]
+ eager_load! if options[:eager_load]
+ autoload! if options[:autoload]
+ load_path! if options[:load_path]
@root.all_paths << self
end
@@ -111,24 +116,30 @@ module Rails
@paths.concat paths
end
- def load_once!
- @load_once = true
- @load_path = true
+ def autoload_once!
+ @autoload_once = true
end
- def load_once?
- @load_once
+ def autoload_once?
+ @autoload_once
end
def eager_load!
@eager_load = true
- @load_path = true
end
def eager_load?
@eager_load
end
+ def autoload!
+ @autoload = true
+ end
+
+ def autoload?
+ @autoload
+ end
+
def load_path!
@load_path = true
end