提交 3c1dab72 编写于 作者: P Pratik Naik

Revert "Modify the Rails::Application::Path object to allow for more concise path definition."

This reverts commit 913bb2f4.

Reason : The server does not start
上级 378a65a9
......@@ -6,8 +6,8 @@ module PathParent
def method_missing(id, *args)
name = id.to_s
if name =~ /^(.*)=$/ || args.any?
@children[$1 || name] = Path.new(@root, *args)
if name =~ /^(.*)=$/
@children[$1] = Path.new(args.first, @root)
elsif path = @children[name]
path
else
......@@ -28,15 +28,17 @@ def initialize(path)
# TODO: Move logic from set_root_path initializer
@path = File.expand_path(path)
@root = self
@all_paths = []
@load_once, @eager_load, @all_paths = [], [], []
end
def load_once
all_paths.map { |path| path.paths if path.load_once? }.compact.flatten.uniq
@load_once.uniq!
@load_once
end
def eager_load
all_paths.map { |path| path.paths if path.eager_load? }.compact.flatten.uniq
@eager_load.uniq!
@eager_load
end
def all_paths
......@@ -45,7 +47,7 @@ def all_paths
end
def load_paths
all_paths.map { |path| path.paths if path.load_path? }.compact.flatten.uniq
all_paths.map { |path| path.paths }.flatten
end
def add_to_load_path
......@@ -53,14 +55,6 @@ def add_to_load_path
$LOAD_PATH.unshift(path) if File.directory?(path)
end
end
def push(*)
raise "Application root can only have one physical path"
end
alias unshift push
alias << push
alias concat push
end
class Path
......@@ -69,18 +63,11 @@ class Path
attr_reader :path
attr_accessor :glob
def initialize(root, *paths)
@options = paths.extract_options!
def initialize(path, root)
@children = {}
@root = root
@paths = paths.flatten
@glob = @options[:glob] || "**/*.rb"
@load_once = @options[:load_once]
@eager_load = @options[:eager_load]
@load_path = @options[:load_path] || @eager_load
@root.all_paths << self
@paths = [path].flatten
@glob = "**/*.rb"
end
def push(path)
......@@ -99,6 +86,7 @@ def concat(paths)
def load_once!
@load_once = true
@root.load_once.push *self.paths
end
def load_once?
......@@ -107,7 +95,8 @@ def load_once?
def eager_load!
@eager_load = true
@load_path = true
@root.all_paths << self
@root.eager_load.push *self.paths
end
def eager_load?
......@@ -116,6 +105,7 @@ def eager_load?
def load_path!
@load_path = true
@root.all_paths << self
end
def load_path?
......
......@@ -17,37 +17,17 @@ def setup
assert_equal ["/foo/bar"], @root.app.to_a
end
test "creating a root level path without assignment" do
@root.app "/foo/bar"
assert_equal ["/foo/bar"], @root.app.to_a
end
test "trying to access a path that does not exist raises NoMethodError" do
assert_raises(NoMethodError) { @root.app }
end
test "relative paths are relative to the paths root" do
@root.app = "app"
assert_equal ["/foo/bar/app"], @root.app.to_a
end
test "relative paths are relative to the paths root without assignment" do
@root.app "app"
assert_equal ["/foo/bar/app"], @root.app.to_a
end
test "creating a child level path" do
@root.app = "/foo/bar"
@root.app.models = "/foo/bar/baz"
assert_equal ["/foo/bar/baz"], @root.app.models.to_a
end
test "creating a child level path without assignment" do
@root.app = "/foo/bar"
@root.app.models "/foo/bar/baz"
assert_equal ["/foo/bar/baz"], @root.app.models.to_a
end
test "child level paths are relative from the root" do
@root.app = "/app"
@root.app.models = "baz"
......@@ -60,11 +40,6 @@ def setup
assert_equal ["/app", "/app2"], @root.app.to_a
end
test "adding multiple physical paths as an array without assignment" do
@root.app "/app", "/app2"
assert_equal ["/app", "/app2"], @root.app.to_a
end
test "adding multiple physical paths using #push" do
@root.app = "/app"
@root.app.push "/app2"
......@@ -91,10 +66,10 @@ def setup
test "the root can only have one physical path" do
assert_raise(RuntimeError) { Rails::Application::Root.new(["/fiz", "/biz"]) }
assert_raise(RuntimeError) { @root.push "/biz" }
assert_raise(RuntimeError) { @root.unshift "/biz" }
assert_raise(RuntimeError) { @root.concat ["/biz"]}
assert_raise(RuntimeError) { @root << "/biz" }
assert_raise(NoMethodError) { @root.push "/biz" }
assert_raise(NoMethodError) { @root.unshift "/biz" }
assert_raise(NoMethodError) { @root.concat ["/biz"]}
assert_raise(NoMethodError) { @root << "/biz" }
end
test "it is possible to add a path that should be loaded only once" do
......@@ -104,19 +79,6 @@ def setup
assert @root.load_once.include?(@root.app.paths.first)
end
test "it is possible to add a path without assignment and specify it should be loaded only once" do
@root.app "/app", :load_once => true
assert @root.app.load_once?
assert @root.load_once.include?("/app")
end
test "it is possible to add multiple paths without assignment and specify it should be loaded only once" do
@root.app "/app", "/app2", :load_once => true
assert @root.app.load_once?
assert @root.load_once.include?("/app")
assert @root.load_once.include?("/app2")
end
test "making a path load_once more than once only includes it once in @root.load_once" do
@root.app = "/app"
@root.app.load_once!
......@@ -124,13 +86,6 @@ def setup
assert_equal 1, @root.load_once.select {|p| p == @root.app.paths.first }.size
end
test "paths added to a load_once path should be added to the load_once collection" do
@root.app = "/app"
@root.app.load_once!
@root.app << "/app2"
assert_equal 2, @root.load_once.size
end
test "it is possible to mark a path as eager" do
@root.app = "/app"
@root.app.eager_load!
......@@ -138,27 +93,6 @@ def setup
assert @root.eager_load.include?(@root.app.paths.first)
end
test "it is possible to add a path without assignment and mark it as eager" do
@root.app "/app", :eager_load => true
assert @root.app.eager_load?
assert @root.eager_load.include?("/app")
end
test "it is possible to add multiple paths without assignment and mark them as eager" do
@root.app "/app", "/app2", :eager_load => true
assert @root.app.eager_load?
assert @root.eager_load.include?("/app")
assert @root.eager_load.include?("/app2")
end
test "it is possible to create a path without assignment and mark it both as eager and load once" do
@root.app "/app", :eager_load => true, :load_once => true
assert @root.app.eager_load?
assert @root.app.load_once?
assert @root.eager_load.include?("/app")
assert @root.load_once.include?("/app")
end
test "making a path eager more than once only includes it once in @root.eager_paths" do
@root.app = "/app"
@root.app.eager_load!
......@@ -166,13 +100,6 @@ def setup
assert_equal 1, @root.eager_load.select {|p| p == @root.app.paths.first }.size
end
test "paths added to a eager_load path should be added to the eager_load collection" do
@root.app = "/app"
@root.app.eager_load!
@root.app << "/app2"
assert_equal 2, @root.eager_load.size
end
test "a path should have a glob that defaults to **/*.rb" do
@root.app = "/app"
assert_equal "**/*.rb", @root.app.glob
......@@ -184,11 +111,6 @@ def setup
assert_equal "*.rb", @root.app.glob
end
test "it should be possible to override a path's default glob without assignment" do
@root.app "/app", :glob => "*.rb"
assert_equal "*.rb", @root.app.glob
end
test "a path can be added to the load path" do
@root.app = "app"
@root.app.load_path!
......@@ -196,12 +118,6 @@ def setup
assert_equal ["/foo/bar/app"], @root.load_paths
end
test "a path can be added to the load path on creation" do
@root.app "/app", :load_path => true
assert @root.app.load_path?
assert_equal ["/app"], @root.load_paths
end
test "adding a path to the eager paths also adds it to the load path" do
@root.app = "app"
@root.app.eager_load!
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册