Skip to content

Commit

Permalink
Deprecation: remove components from controller paths. Canonicalize RA…
Browse files Browse the repository at this point in the history
…ILS_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
  • Loading branch information
jeremy committed Mar 18, 2007
1 parent 27ba5ed commit 2632664
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 30 deletions.
4 changes: 4 additions & 0 deletions 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]
Expand Down
11 changes: 1 addition & 10 deletions 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")
Expand Down
59 changes: 40 additions & 19 deletions 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)
Expand Down Expand Up @@ -193,7 +196,7 @@ def load_plugins
end
end
ensure_all_registered_plugins_are_loaded!
$LOAD_PATH.uniq!
$LOAD_PATH.uniq!
end

# Loads the environment specified by Configuration#environment_path, which
Expand Down Expand Up @@ -307,10 +310,10 @@ def initialize_whiny_nils

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
Expand All @@ -336,11 +339,11 @@ def after_initialize
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?
Expand All @@ -362,6 +365,9 @@ def ensure_all_registered_plugins_are_loaded!
# 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

Expand Down Expand Up @@ -441,21 +447,23 @@ class Configuration
# The path to the root of the plugins directory. By default, it is in
# <tt>vendor/plugins</tt>.
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 <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>.
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

# 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
Expand All @@ -477,6 +485,23 @@ def initialize
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.
Expand Down Expand Up @@ -536,10 +561,6 @@ def framework_paths
end

private
def root_path
::RAILS_ROOT
end

def framework_root_path
defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
end
Expand Down Expand Up @@ -596,7 +617,7 @@ def default_view_path
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
Expand Down Expand Up @@ -624,11 +645,11 @@ def default_plugins
def default_plugin_paths
["#{root_path}/vendor/plugins"]
end

def default_plugin_locators
[Plugin::FileSystemLocator]
end

def default_plugin_loader
Plugin::Loader
end
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/railties_path.rb
@@ -1 +1 @@
RAILTIES_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
RAILTIES_PATH = File.join(File.dirname(__FILE__), '..')

1 comment on commit 2632664

@rnhurt
Copy link

@rnhurt rnhurt commented on 2632664 Sep 13, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on building the Debian package for Redmine and we have a situation where the …/vendor/rails directory is actually a symlink to the Debian Rails install in /usr/share/rails. In order to get it to work we had to run RAILS_ROOT through a File.expand_path() 1. According to the above code you guys are specifically removing the expand_path() except for Windows. Are we doing something wrong? Is there a better way to deal with symlinks in RAILS_ROOT?

Thanx!
Richard

BTW: I’m running Debian Lenny on x86. The Radiant folks have also changed their boot.rb to use expand_path() 2.

1 http://www.redmine.org/repositories/diff/redmine/trunk/config/boot.rb?rev=1820
2 http://github.com/radiant/radiant/tree/197501977dadb427decce9fa997b388afc1431d4/config/boot.rb

Please sign in to comment.