From 2370e87ae0babf0fb4b21254c8120f7a93189d40 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 30 Sep 2009 12:05:34 -0700 Subject: Remove all calls to Rails::Initializer from boot.rb This is starting a refactor of the rails initialization process. The boot.rb file will not remain the same. --- .../generators/rails/app/templates/config/boot.rb | 47 +++++++++++++++++++--- .../rails/app/templates/config/environment.rb | 4 +- railties/lib/rails/initializer.rb | 23 ++--------- 3 files changed, 45 insertions(+), 29 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/rails/app/templates/config/boot.rb b/railties/lib/rails/generators/rails/app/templates/config/boot.rb index d2652af9b0..52086fbc7d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/boot.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/boot.rb @@ -4,6 +4,11 @@ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) module Rails + # Mark the version of Rails that generated the boot.rb file. This is + # a temporary solution and will most likely be removed as Rails 3.0 + # comes closer. + BOOTSTRAP_VERSION = "3.0" + class << self def boot! unless booted? @@ -36,20 +41,50 @@ module Rails class Boot def run load_initializer - Rails::Initializer.run(:set_load_path) + set_load_paths + end + + def set_load_paths + %w( + railties + railties/lib + activesupport/lib + actionpack/lib + activerecord/lib + actionmailer/lib + activeresource/lib + actionwebservice/lib + ).reverse_each do |path| + path = "#{framework_root_path}/#{path}" + $LOAD_PATH.unshift(path) if File.directory?(path) + $LOAD_PATH.uniq! + end + end + + def framework_root_path + defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{RAILS_ROOT}/vendor/rails" end end class VendorBoot < Boot def load_initializer - # activesupport/lib - %w(railties/lib).each do |path| - $:.unshift("#{RAILS_ROOT}/vendor/rails/#{path}") - end + $:.unshift("#{framework_root_path}/railties/lib") require "rails" - Rails::Initializer.run(:install_gem_spec_stubs) + install_gem_spec_stubs Rails::GemDependency.add_frozen_gem_path end + + def install_gem_spec_stubs + begin; require "rubygems"; rescue LoadError; return; end + + %w(rails activesupport activerecord actionpack actionmailer activeresource).each do |stub| + Gem.loaded_specs[stub] ||= Gem::Specification.new do |s| + s.name = stub + s.version = Rails::VERSION::STRING + s.loaded_from = "" + end + end + end end class GemBoot < Boot diff --git a/railties/lib/rails/generators/rails/app/templates/config/environment.rb b/railties/lib/rails/generators/rails/app/templates/config/environment.rb index 2f2d1162c0..adb3a3060a 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environment.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/environment.rb @@ -6,9 +6,7 @@ # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') -module <%= app_name.camelize %>; end - -<%= app_name.camelize %>::Application = Rails::Initializer.run do |config| +Rails::Initializer.run do |config| # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb index f75bd917bf..2d63ac4d39 100644 --- a/railties/lib/rails/initializer.rb +++ b/railties/lib/rails/initializer.rb @@ -123,33 +123,16 @@ module Rails require 'rails/ruby_version_check' 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 - # the Gem version of Rails shouldn't be loaded. - Initializer.default.add :install_gem_spec_stubs do - unless Rails.respond_to?(:vendor_rails?) + # Bail if boot.rb is outdated + Initializer.default.add :freak_out_if_boot_rb_is_outdated do + unless defined?(Rails::BOOTSTRAP_VERSION) abort %{Your config/boot.rb is outdated: Run "rake rails:update".} end - - if Rails.vendor_rails? - begin; require "rubygems"; rescue LoadError; return; end - - %w(rails activesupport activerecord actionpack actionmailer activeresource).each do |stub| - Gem.loaded_specs[stub] ||= Gem::Specification.new do |s| - s.name = stub - s.version = Rails::VERSION::STRING - s.loaded_from = "" - end - end - end end # Set the $LOAD_PATH based on the value of # Configuration#load_paths. Duplicates are removed. Initializer.default.add :set_load_path do - # 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 -- cgit v1.2.3