aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-26 17:32:05 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-26 17:32:05 -0700
commit188a892c5a097ee6d62249d048a6be7d2dfe9649 (patch)
tree6ef8769019e1f294156dd58551ec6656a37d4385 /railties/lib
parent4153c6b720563e1c43bb96e95f0ff5fbd59d6be7 (diff)
downloadrails-188a892c5a097ee6d62249d048a6be7d2dfe9649.tar.gz
rails-188a892c5a097ee6d62249d048a6be7d2dfe9649.tar.bz2
rails-188a892c5a097ee6d62249d048a6be7d2dfe9649.zip
Starting to replace scattered path configuration settings with the path object
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/initializer.rb27
-rw-r--r--railties/lib/rails/configuration.rb33
-rw-r--r--railties/lib/rails/paths.rb43
-rw-r--r--railties/lib/railties_path.rb2
4 files changed, 78 insertions, 27 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 697ccfa0dc..cd23158e98 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -5,6 +5,7 @@ require 'railties_path'
require 'rails/version'
require 'rails/gem_dependency'
require 'rails/rack'
+require 'rails/paths'
require 'rails/core'
require 'rails/configuration'
@@ -112,24 +113,6 @@ module Rails
require 'ruby_version_check'
end
- Initializer.default.add :set_root_path do
- raise 'RAILS_ROOT is not set' unless defined?(RAILS_ROOT)
- raise 'RAILS_ROOT is not a directory' unless File.directory?(RAILS_ROOT)
-
- configuration.root_path =
- # Pathname is incompatible with Windows, but Windows doesn't have
- # real symlinks so File.expand_path is safe.
- if RUBY_PLATFORM =~ /(:?mswin|mingw)/
- File.expand_path(RAILS_ROOT)
-
- # Otherwise use Pathname#realpath which respects symlinks.
- else
- Pathname.new(RAILS_ROOT).realpath.to_s
- end
-
- RAILS_ROOT.replace configuration.root_path
- end
-
# If Rails is vendored and RubyGems is available, install stub GemSpecs
# for Rails, Active Support, Active Record, Action Pack, Action Mailer, and
# Active Resource. This allows Gem plugins to depend on Rails even when
@@ -158,8 +141,9 @@ module Rails
# Set the <tt>$LOAD_PATH</tt> based on the value of
# Configuration#load_paths. Duplicates are removed.
Initializer.default.add :set_load_path do
- load_paths = configuration.load_paths + configuration.framework_paths
- load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
+ # TODO: Think about unifying this with the general Rails paths
+ configuration.framework_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
+ configuration.paths.add_to_load_path
$LOAD_PATH.uniq!
end
@@ -221,6 +205,8 @@ module Rails
Initializer.default.add :load_environment do
silence_warnings do
next if @environment_loaded
+ next unless File.file?(configuration.environment_path)
+
@environment_loaded = true
config = configuration
@@ -564,6 +550,7 @@ Run `rake gems:install` to install the missing gems.
# Eager load application classes
Initializer.default.add :load_application_classes do
next if $rails_rake_task
+
if configuration.cache_classes
configuration.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index fdb071fc18..59132efe98 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -10,7 +10,7 @@ module Rails
:log_path, :log_level, :logger, :preload_frameworks,
:database_configuration_file, :cache_store, :time_zone,
:view_path, :metals, :controller_paths, :routes_configuration_file,
- :eager_load_paths, :dependency_loading
+ :eager_load_paths, :dependency_loading, :paths
def initialize
set_root_path!
@@ -61,7 +61,36 @@ module Rails
Pathname.new(RAILS_ROOT).realpath.to_s
end
- RAILS_ROOT.replace self.root_path
+ @paths = Rails::Application::Root.new(root_path)
+ @paths.app = "app"
+ @paths.app.metals = "app/metal"
+ @paths.app.models = "app/models"
+ @paths.app.controllers = "app/controllers"
+ @paths.app.helpers = "app/helpers"
+ @paths.app.services = "app/services"
+ @paths.lib = "lib"
+ @paths.vendor = "vendor"
+ @paths.vendor.plugins = "vendor/plugins"
+ @paths.cache = "tmp/cache"
+ @paths.config = "config"
+ @paths.config.locales = "config/locales"
+ @paths.config.environments = "config/environments"
+
+ @paths.app.controllers.push *builtin_directories
+
+ @paths.app.load_path!
+ @paths.app.metals.load_path!
+ @paths.app.models.eager_load!
+ @paths.app.controllers.eager_load!
+ @paths.app.helpers.eager_load!
+ @paths.app.services.load_path!
+ @paths.app.metals.eager_load!
+ @paths.lib.load_path!
+ @paths.vendor.load_path!
+
+ @paths.config.environments.glob = "#{RAILS_ENV}.rb"
+
+ RAILS_ROOT.replace root_path
end
# Enable threaded mode. Allows concurrent requests to controller actions and
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)
diff --git a/railties/lib/railties_path.rb b/railties/lib/railties_path.rb
index a298a4cc27..b729c095c8 100644
--- a/railties/lib/railties_path.rb
+++ b/railties/lib/railties_path.rb
@@ -1 +1 @@
-RAILTIES_PATH = File.join(File.dirname(__FILE__), '..')
+RAILTIES_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))