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