From 2632664f6459b387f64ba473712af049e543beb4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 18 Mar 2007 13:35:16 +0000 Subject: Deprecation: remove components from controller paths. Canonicalize RAILS_ROOT by using File.expand_path on Windows, which doesn't have to worry about symlinks, and Pathname#realpath elsewhere, which respects symlinks in relative paths but is incompatible with Windows. Closes #6755. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6445 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/CHANGELOG | 4 +++ railties/environments/boot.rb | 11 +------- railties/lib/initializer.rb | 59 +++++++++++++++++++++++++++++-------------- railties/lib/railties_path.rb | 2 +- 4 files changed, 46 insertions(+), 30 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 12d56e0ccb..9eff591e53 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,9 @@ *SVN* +* Canonicalize RAILS_ROOT by using File.expand_path on Windows, which doesn't have to worry about symlinks, and Pathname#realpath elsewhere, which respects symlinks in relative paths but is incompatible with Windows. #6755 [Jeremy Kemper, trevor] + +* Deprecation: remove components from controller paths. [Jeremy Kemper] + * Add environment variable RAILS_DEFAULT_DATABASE, which allows the builtin default of 'mysql' to be overridden. [Nicholas Seckar] * Windows: include MinGW in RUBY_PLATFORM check. #2982 [okkez000@gmail.com, Kaspar Schiess] diff --git a/railties/environments/boot.rb b/railties/environments/boot.rb index b7af0c35c7..901deb666d 100644 --- a/railties/environments/boot.rb +++ b/railties/environments/boot.rb @@ -1,15 +1,6 @@ # Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb -unless defined?(RAILS_ROOT) - root_path = File.join(File.dirname(__FILE__), '..') - - unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ - require 'pathname' - root_path = Pathname.new(root_path).cleanpath(true).to_s - end - - RAILS_ROOT = root_path -end +RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) unless defined?(Rails::Initializer) if File.directory?("#{RAILS_ROOT}/vendor/rails") diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 1e01758729..15ae80f1cf 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -1,9 +1,12 @@ require 'logger' require 'set' -require File.join(File.dirname(__FILE__), 'railties_path') -require File.join(File.dirname(__FILE__), 'rails/version') -require File.join(File.dirname(__FILE__), 'rails/plugin/locator') -require File.join(File.dirname(__FILE__), 'rails/plugin/loader') +require 'pathname' + +$LOAD_PATH.unshift File.dirname(__FILE__) +require 'railties_path' +require 'rails/version' +require 'rails/plugin/locator' +require 'rails/plugin/loader' RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV) @@ -193,7 +196,7 @@ module Rails end end ensure_all_registered_plugins_are_loaded! - $LOAD_PATH.uniq! + $LOAD_PATH.uniq! end # Loads the environment specified by Configuration#environment_path, which @@ -307,10 +310,10 @@ module Rails def initialize_temporary_directories if configuration.frameworks.include?(:action_controller) - session_path = "#{RAILS_ROOT}/tmp/sessions/" + session_path = "#{configuration.root_path}/tmp/sessions/" ActionController::Base.session_options[:tmpdir] = File.exist?(session_path) ? session_path : Dir::tmpdir - cache_path = "#{RAILS_ROOT}/tmp/cache/" + cache_path = "#{configuration.root_path}/tmp/cache/" if File.exist?(cache_path) ActionController::Base.fragment_cache_store = :file_store, cache_path end @@ -336,11 +339,11 @@ module Rails end def load_application_initializers - Dir["#{RAILS_ROOT}/config/initializers/**/*.rb"].each do |initializer| + Dir["#{configuration.root_path}/config/initializers/**/*.rb"].each do |initializer| load(initializer) end end - + private def ensure_all_registered_plugins_are_loaded! unless configuration.plugins.nil? @@ -362,6 +365,9 @@ module Rails # config = Rails::Configuration.new # Rails::Initializer.run(:process, config) class Configuration + # The application's base directory. + attr_reader :root_path + # A stub for setting options on ActionController::Base attr_accessor :action_controller @@ -441,14 +447,14 @@ module Rails # The path to the root of the plugins directory. By default, it is in # vendor/plugins. attr_accessor :plugin_paths - + # The classes that handle finding the desired plugins that you'd like to load for # your application. By default it is the Rails::Plugin::FileSystemLocator which finds # plugins to load in vendor/plugins. You can hook into gem location by subclassing # Rails::Plugin::Locator and adding it onto the list of plugin_locators. attr_accessor :plugin_locators - - # The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but + + # The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but # a sub class would have access to fine grained modification of the loading behavior. See # the implementation of Rails::Plugin::Loader for more details. attr_accessor :plugin_loader @@ -456,6 +462,8 @@ module Rails # Create a new Configuration instance, initialized with the default # values. def initialize + set_root_path! + self.frameworks = default_frameworks self.load_paths = default_load_paths self.load_once_paths = default_load_once_paths @@ -477,6 +485,23 @@ module Rails end end + # Set the root_path to RAILS_ROOT and canonicalize it. + def set_root_path! + raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT) + raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT) + + @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 + end + # Loads and returns the contents of the #database_configuration_file. The # contents of the file are processed via ERB before being sent through # YAML::load. @@ -536,10 +561,6 @@ module Rails end private - def root_path - ::RAILS_ROOT - end - def framework_root_path defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails" end @@ -596,7 +617,7 @@ module Rails end def default_controller_paths - paths = [ File.join(root_path, 'app', 'controllers'), File.join(root_path, 'components') ] + paths = [File.join(root_path, 'app', 'controllers')] paths.concat builtin_directories paths end @@ -624,11 +645,11 @@ module Rails def default_plugin_paths ["#{root_path}/vendor/plugins"] end - + def default_plugin_locators [Plugin::FileSystemLocator] end - + def default_plugin_loader Plugin::Loader end diff --git a/railties/lib/railties_path.rb b/railties/lib/railties_path.rb index 817940504d..a298a4cc27 100644 --- a/railties/lib/railties_path.rb +++ b/railties/lib/railties_path.rb @@ -1 +1 @@ -RAILTIES_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..')) \ No newline at end of file +RAILTIES_PATH = File.join(File.dirname(__FILE__), '..') -- cgit v1.2.3