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