]> git.openstreetmap.org Git - rails.git/blob - config/boot.rb
fix broken YAML
[rails.git] / config / boot.rb
1 # Don't change this file!
2 # Configure your app in config/environment.rb and config/environments/*.rb
3
4 RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
6 module Rails
7   class << self
8     def boot!
9       unless booted?
10         preinitialize
11         pick_boot.run
12       end
13     end
14
15     def booted?
16       defined? Rails::Initializer
17     end
18
19     def pick_boot
20       (vendor_rails? ? VendorBoot : GemBoot).new
21     end
22
23     def vendor_rails?
24       File.exist?("#{RAILS_ROOT}/vendor/rails")
25     end
26
27     def preinitialize
28       load(preinitializer_path) if File.exists?(preinitializer_path)
29     end
30
31     def preinitializer_path
32       "#{RAILS_ROOT}/config/preinitializer.rb"
33     end
34   end
35
36   class Boot
37     def run
38       load_initializer
39       Rails::Initializer.run(:set_load_path)
40     end
41   end
42
43   class VendorBoot < Boot
44     def load_initializer
45       require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46     end
47   end
48
49   class GemBoot < Boot
50     def load_initializer
51       self.class.load_rubygems
52       load_rails_gem
53       require 'initializer'
54     end
55
56     def load_rails_gem
57       if version = self.class.gem_version
58         gem 'rails', version
59       else
60         gem 'rails'
61       end
62     rescue Gem::LoadError => load_error
63       $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.)
64       exit 1
65     end
66
67     class << self
68       def rubygems_version
69         Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
70       end
71
72       def gem_version
73         if defined? RAILS_GEM_VERSION
74           RAILS_GEM_VERSION
75         elsif ENV.include?('RAILS_GEM_VERSION')
76           ENV['RAILS_GEM_VERSION']
77         else
78           parse_gem_version(read_environment_rb)
79         end
80       end
81
82       def load_rubygems
83         require 'rubygems'
84
85         unless rubygems_version >= '0.9.4'
86           $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
87           exit 1
88         end
89
90       rescue LoadError
91         $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
92         exit 1
93       end
94
95       def parse_gem_version(text)
96         $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*'([!~<>=]*\s*[\d.]+)'/
97       end
98
99       private
100         def read_environment_rb
101           File.read("#{RAILS_ROOT}/config/environment.rb")
102         end
103     end
104   end
105 end
106
107 # All that for this:
108 Rails.boot!