empty app rails 1.99.0 (aka Rails 2.0 preview)
[rails-skeleton.git] / config / boot.rb
blob759129044725edc281df8b332a6187fe1f6a1b44
1 # Don't change this file!
2 # Configure your app in config/environment.rb and config/environments/*.rb
4 RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
6 module Rails
7   class << self
8     def boot!
9       pick_boot.run unless booted?
10     end
12     def booted?
13       defined? Rails::Initializer
14     end
16     def pick_boot
17       (vendor_rails? ? VendorBoot : GemBoot).new
18     end
20     def vendor_rails?
21       File.exist?("#{RAILS_ROOT}/vendor/rails")
22     end
23   end
25   class Boot
26     def run
27       load_initializer
28       Rails::Initializer.run(:set_load_path)
29     end
30   end
32   class VendorBoot < Boot
33     def load_initializer
34       require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
35     end
36   end
38   class GemBoot < Boot
39     def load_initializer
40       self.class.load_rubygems
41       load_rails_gem
42       require 'initializer'
43     end
45     def load_rails_gem
46       if version = self.class.gem_version
47         gem 'rails', "=#{version}"
48       else
49         gem 'rails'
50       end
51     rescue Gem::LoadError => load_error
52       $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
53       exit 1
54     end
56     class << self
57       def rubygems_version
58         Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
59       end
61       def gem_version
62         if defined? RAILS_GEM_VERSION
63           RAILS_GEM_VERSION
64         elsif ENV.include?('RAILS_GEM_VERSION')
65           ENV['RAILS_GEM_VERSION']
66         else
67           parse_gem_version(read_environment_rb)
68         end
69       end
71       def load_rubygems
72         require 'rubygems'
74         unless rubygems_version >= '0.9.4'
75           $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
76           exit 1
77         end
79       rescue LoadError
80         $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
81         exit 1
82       end
84       def parse_gem_version(text)
85         $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*'([\d.]+)'/
86       end
88       private
89         def read_environment_rb
90           File.read("#{RAILS_ROOT}/config/environment.rb")
91         end
92     end
93   end
94 end
96 # All that for this:
97 Rails.boot!