Permalink
Browse files

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.
  • Loading branch information...
1 parent 34aae6d commit 2370e87ae0babf0fb4b21254c8120f7a93189d40 Carl Lerche committed Sep 30, 2009
View
47 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 @@ def preinitializer_path
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
View
4 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.
View
23 railties/lib/rails/initializer.rb
@@ -123,33 +123,16 @@ def self.run(initializer = nil, config = nil)
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 <tt>$LOAD_PATH</tt> 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
View
9 railties/test/boot_test.rb
@@ -48,13 +48,6 @@ def test_boot_gem_rails_otherwise
Rails::GemBoot.any_instance.expects(:run).returns('result')
assert_equal 'result', Rails.boot!
end
-
- def test_run_loads_initializer_and_sets_load_path
- boot = Rails::Boot.new
- boot.expects(:load_initializer)
- Rails::Initializer.expects(:run).with(:set_load_path)
- boot.run
- end
end
class VendorBootTest < Test::Unit::TestCase
@@ -63,7 +56,7 @@ class VendorBootTest < Test::Unit::TestCase
def test_load_initializer_requires_from_vendor_rails
boot = VendorBoot.new
boot.expects(:require).with("rails")
- Rails::Initializer.expects(:run).with(:install_gem_spec_stubs)
+ boot.expects(:install_gem_spec_stubs)
Rails::GemDependency.expects(:add_frozen_gem_path)
boot.load_initializer
end
View
16 railties/test/initializer/boot_test.rb
@@ -0,0 +1,16 @@
+require "isolation/abstract_unit"
+
+module BootTests
+ class GemBooting < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ # build_app
+ # boot_rails
+ end
+
+ test "booting rails sets the load paths correctly" do
+ # This test is pending reworking the boot process
+ end
+ end
+end
View
20 railties/test/isolation/abstract_unit.rb
@@ -97,20 +97,16 @@ def controller(name, contents)
end
def boot_rails
- # return if defined?(RAILS)
- # TODO: Get this working with boot.rb
- $:.unshift "#{RAILS_FRAMEWORK_ROOT}/railties/lib"
- Object.class_eval <<-RUBY
- RAILS_ROOT = "#{app_path}"
- module ::Rails
- def self.vendor_rails?
- true
- end
+ # TMP mega hax to prevent boot.rb from actually booting
+ Object.class_eval <<-RUBY, __FILE__, __LINE__+1
+ module Rails
+ Initializer = 'lol'
+ require "#{app_path}/config/boot"
+ remove_const(:Initializer)
+ booter = VendorBoot.new
+ booter.run
end
RUBY
- require "rails"
- Rails::Initializer.run(:install_gem_spec_stubs)
- Rails::GemDependency.add_frozen_gem_path
end
end
end

0 comments on commit 2370e87

Please sign in to comment.