@@ -1,122 +1,127 | |||
|
1 | 1 | # Don't change this file! |
|
2 | 2 | # Configure your app in config/environment.rb and config/environments/*.rb |
|
3 | 3 | |
|
4 | if RUBY_VERSION >= '1.9' | |
|
5 | require 'yaml' | |
|
6 | YAML::ENGINE.yamler = 'syck' | |
|
7 | end | |
|
8 | ||
|
4 | 9 | RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) |
|
5 | 10 | |
|
6 | 11 | module Rails |
|
7 | 12 | class << self |
|
8 | 13 | def boot! |
|
9 | 14 | unless booted? |
|
10 | 15 | preinitialize |
|
11 | 16 | pick_boot.run |
|
12 | 17 | end |
|
13 | 18 | end |
|
14 | 19 | |
|
15 | 20 | def booted? |
|
16 | 21 | defined? Rails::Initializer |
|
17 | 22 | end |
|
18 | 23 | |
|
19 | 24 | def pick_boot |
|
20 | 25 | (vendor_rails? ? VendorBoot : GemBoot).new |
|
21 | 26 | end |
|
22 | 27 | |
|
23 | 28 | def vendor_rails? |
|
24 | 29 | File.exist?("#{RAILS_ROOT}/vendor/rails") |
|
25 | 30 | end |
|
26 | 31 | |
|
27 | 32 | def preinitialize |
|
28 | 33 | load(preinitializer_path) if File.exist?(preinitializer_path) |
|
29 | 34 | end |
|
30 | 35 | |
|
31 | 36 | def preinitializer_path |
|
32 | 37 | "#{RAILS_ROOT}/config/preinitializer.rb" |
|
33 | 38 | end |
|
34 | 39 | end |
|
35 | 40 | |
|
36 | 41 | class Boot |
|
37 | 42 | def run |
|
38 | 43 | load_initializer |
|
39 | 44 | Rails::Initializer.run(:set_load_path) |
|
40 | 45 | end |
|
41 | 46 | end |
|
42 | 47 | |
|
43 | 48 | class VendorBoot < Boot |
|
44 | 49 | def load_initializer |
|
45 | 50 | require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" |
|
46 | 51 | Rails::Initializer.run(:install_gem_spec_stubs) |
|
47 | 52 | Rails::GemDependency.add_frozen_gem_path |
|
48 | 53 | end |
|
49 | 54 | end |
|
50 | 55 | |
|
51 | 56 | class GemBoot < Boot |
|
52 | 57 | def load_initializer |
|
53 | 58 | self.class.load_rubygems |
|
54 | 59 | load_rails_gem |
|
55 | 60 | require 'initializer' |
|
56 | 61 | end |
|
57 | 62 | |
|
58 | 63 | def load_rails_gem |
|
59 | 64 | if version = self.class.gem_version |
|
60 | 65 | gem 'rails', version |
|
61 | 66 | else |
|
62 | 67 | gem 'rails' |
|
63 | 68 | end |
|
64 | 69 | rescue Gem::LoadError => load_error |
|
65 | 70 | $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.) |
|
66 | 71 | exit 1 |
|
67 | 72 | end |
|
68 | 73 | |
|
69 | 74 | class << self |
|
70 | 75 | def rubygems_version |
|
71 | 76 | Gem::RubyGemsVersion rescue nil |
|
72 | 77 | end |
|
73 | 78 | |
|
74 | 79 | def gem_version |
|
75 | 80 | if defined? RAILS_GEM_VERSION |
|
76 | 81 | RAILS_GEM_VERSION |
|
77 | 82 | elsif ENV.include?('RAILS_GEM_VERSION') |
|
78 | 83 | ENV['RAILS_GEM_VERSION'] |
|
79 | 84 | else |
|
80 | 85 | parse_gem_version(read_environment_rb) |
|
81 | 86 | end |
|
82 | 87 | end |
|
83 | 88 | |
|
84 | 89 | def load_rubygems |
|
85 | 90 | min_version = '1.3.2' |
|
86 | 91 | require 'rubygems' |
|
87 | 92 | unless rubygems_version >= min_version |
|
88 | 93 | $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) |
|
89 | 94 | exit 1 |
|
90 | 95 | end |
|
91 | 96 | |
|
92 | 97 | rescue LoadError |
|
93 | 98 | $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) |
|
94 | 99 | exit 1 |
|
95 | 100 | end |
|
96 | 101 | |
|
97 | 102 | def parse_gem_version(text) |
|
98 | 103 | $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ |
|
99 | 104 | end |
|
100 | 105 | |
|
101 | 106 | private |
|
102 | 107 | def read_environment_rb |
|
103 | 108 | File.read("#{RAILS_ROOT}/config/environment.rb") |
|
104 | 109 | end |
|
105 | 110 | end |
|
106 | 111 | end |
|
107 | 112 | end |
|
108 | 113 | |
|
109 | 114 | # TODO: Workaround for #7013 to be removed for 1.2.0 |
|
110 | 115 | # Loads i18n 0.4.2 before Rails loads any more recent gem |
|
111 | 116 | # 0.5.0 is not compatible with the old interpolation syntax |
|
112 | 117 | # Plugins will have to migrate to the new syntax for 1.2.0 |
|
113 | 118 | require 'rubygems' |
|
114 | 119 | begin |
|
115 | 120 | gem 'i18n', '0.4.2' |
|
116 | 121 | rescue Gem::LoadError => load_error |
|
117 | 122 | $stderr.puts %(Missing the i18n 0.4.2 gem. Please `gem install -v=0.4.2 i18n`) |
|
118 | 123 | exit 1 |
|
119 | 124 | end |
|
120 | 125 | |
|
121 | 126 | # All that for this: |
|
122 | 127 | Rails.boot! |
General Comments 0
You need to be logged in to leave comments.
Login now