From 188a892c5a097ee6d62249d048a6be7d2dfe9649 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 26 Jun 2009 17:32:05 -0700 Subject: Starting to replace scattered path configuration settings with the path object --- railties/lib/rails/paths.rb | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'railties/lib/rails/paths.rb') diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 0b43725e32..aada7d4a56 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -19,7 +19,7 @@ module Rails class Root include PathParent - attr_reader :path, :load_once, :eager_load + attr_reader :path def initialize(path) raise unless path.is_a?(String) @@ -28,7 +28,32 @@ module Rails # TODO: Move logic from set_root_path initializer @path = File.expand_path(path) @root = self - @load_once, @eager_load = Set.new, Set.new + @load_once, @eager_load, @all_paths = [], [], [] + end + + def load_once + @load_once.uniq! + @load_once + end + + def eager_load + @eager_load.uniq! + @eager_load + end + + def all_paths + @all_paths.uniq! + @all_paths + end + + def load_paths + all_paths.map { |path| path.paths }.flatten + end + + def add_to_load_path + load_paths.reverse_each do |path| + $LOAD_PATH.unshift(path) if File.directory?(path) + end end end @@ -57,7 +82,7 @@ module Rails def load_once! @load_once = true - @root.load_once << self + @root.load_once.push *self.paths end def load_once? @@ -66,13 +91,23 @@ module Rails def eager_load! @eager_load = true - @root.eager_load << self + @root.all_paths << self + @root.eager_load.push *self.paths end def eager_load? @eager_load end + def load_path! + @load_path = true + @root.all_paths << self + end + + def load_path? + @load_path + end + def paths @paths.map do |path| path.index('/') == 0 ? path : File.join(@root.path, path) -- cgit v1.2.3