1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Jeremy Kemper 2007-03-18 13:35:16 +00:00
parent 27ba5edef1
commit 2632664f64
4 changed files with 46 additions and 30 deletions

View file

@ -1,5 +1,9 @@
*SVN* *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] * 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] * Windows: include MinGW in RUBY_PLATFORM check. #2982 [okkez000@gmail.com, Kaspar Schiess]

View file

@ -1,15 +1,6 @@
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb # Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
unless defined?(RAILS_ROOT) RAILS_ROOT = "#{File.dirname(__FILE__)}/.." 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
unless defined?(Rails::Initializer) unless defined?(Rails::Initializer)
if File.directory?("#{RAILS_ROOT}/vendor/rails") if File.directory?("#{RAILS_ROOT}/vendor/rails")

View file

@ -1,9 +1,12 @@
require 'logger' require 'logger'
require 'set' require 'set'
require File.join(File.dirname(__FILE__), 'railties_path') require 'pathname'
require File.join(File.dirname(__FILE__), 'rails/version')
require File.join(File.dirname(__FILE__), 'rails/plugin/locator') $LOAD_PATH.unshift File.dirname(__FILE__)
require File.join(File.dirname(__FILE__), 'rails/plugin/loader') 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) RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
@ -193,7 +196,7 @@ module Rails
end end
end end
ensure_all_registered_plugins_are_loaded! ensure_all_registered_plugins_are_loaded!
$LOAD_PATH.uniq! $LOAD_PATH.uniq!
end end
# Loads the environment specified by Configuration#environment_path, which # Loads the environment specified by Configuration#environment_path, which
@ -307,10 +310,10 @@ module Rails
def initialize_temporary_directories def initialize_temporary_directories
if configuration.frameworks.include?(:action_controller) 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 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) if File.exist?(cache_path)
ActionController::Base.fragment_cache_store = :file_store, cache_path ActionController::Base.fragment_cache_store = :file_store, cache_path
end end
@ -336,11 +339,11 @@ module Rails
end end
def load_application_initializers 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) load(initializer)
end end
end end
private private
def ensure_all_registered_plugins_are_loaded! def ensure_all_registered_plugins_are_loaded!
unless configuration.plugins.nil? unless configuration.plugins.nil?
@ -362,6 +365,9 @@ module Rails
# config = Rails::Configuration.new # config = Rails::Configuration.new
# Rails::Initializer.run(:process, config) # Rails::Initializer.run(:process, config)
class Configuration class Configuration
# The application's base directory.
attr_reader :root_path
# A stub for setting options on ActionController::Base # A stub for setting options on ActionController::Base
attr_accessor :action_controller attr_accessor :action_controller
@ -441,14 +447,14 @@ module Rails
# The path to the root of the plugins directory. By default, it is in # The path to the root of the plugins directory. By default, it is in
# <tt>vendor/plugins</tt>. # <tt>vendor/plugins</tt>.
attr_accessor :plugin_paths attr_accessor :plugin_paths
# The classes that handle finding the desired plugins that you'd like to load for # 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 # your application. By default it is the Rails::Plugin::FileSystemLocator which finds
# plugins to load in <tt>vendor/plugins</tt>. You can hook into gem location by subclassing # plugins to load in <tt>vendor/plugins</tt>. You can hook into gem location by subclassing
# Rails::Plugin::Locator and adding it onto the list of <tt>plugin_locators</tt>. # Rails::Plugin::Locator and adding it onto the list of <tt>plugin_locators</tt>.
attr_accessor :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 # a sub class would have access to fine grained modification of the loading behavior. See
# the implementation of Rails::Plugin::Loader for more details. # the implementation of Rails::Plugin::Loader for more details.
attr_accessor :plugin_loader attr_accessor :plugin_loader
@ -456,6 +462,8 @@ module Rails
# Create a new Configuration instance, initialized with the default # Create a new Configuration instance, initialized with the default
# values. # values.
def initialize def initialize
set_root_path!
self.frameworks = default_frameworks self.frameworks = default_frameworks
self.load_paths = default_load_paths self.load_paths = default_load_paths
self.load_once_paths = default_load_once_paths self.load_once_paths = default_load_once_paths
@ -477,6 +485,23 @@ module Rails
end end
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 # Loads and returns the contents of the #database_configuration_file. The
# contents of the file are processed via ERB before being sent through # contents of the file are processed via ERB before being sent through
# YAML::load. # YAML::load.
@ -536,10 +561,6 @@ module Rails
end end
private private
def root_path
::RAILS_ROOT
end
def framework_root_path def framework_root_path
defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails" defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
end end
@ -596,7 +617,7 @@ module Rails
end end
def default_controller_paths 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.concat builtin_directories
paths paths
end end
@ -624,11 +645,11 @@ module Rails
def default_plugin_paths def default_plugin_paths
["#{root_path}/vendor/plugins"] ["#{root_path}/vendor/plugins"]
end end
def default_plugin_locators def default_plugin_locators
[Plugin::FileSystemLocator] [Plugin::FileSystemLocator]
end end
def default_plugin_loader def default_plugin_loader
Plugin::Loader Plugin::Loader
end end

View file

@ -1 +1 @@
RAILTIES_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..')) RAILTIES_PATH = File.join(File.dirname(__FILE__), '..')