rails / rails

Ruby on Rails

This URL has Read+Write access

bohford (author)
Wed Sep 09 22:25:23 -0700 2009
jeremy (committer)
Thu Sep 10 17:41:18 -0700 2009
commit  81d828a14c82b882e31612431a56f830bdc1076f
tree    1ae47e0c24a09599a716f9dc81660a26e1d7c8ec
parent  5b8b41732f385131d4e1f1a8862d71f44dcc992d
rails / railties / environments / boot.rb
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 1 # Don't change this file!
2 # Configure your app in config/environment.rb and config/environments/*.rb
9d88348e » dhh 2005-12-07 Warn people not to change b... 3
2632664f » jeremy 2007-03-18 Deprecation: remove compone... Comment 4 RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
bc011df2 » dhh 2005-09-03 Moved all the shared tasks ... 5
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 6 module Rails
7 class << self
8 def boot!
4249ffe2 » jeremy 2007-11-16 Load config/preinitializer.... 9 unless booted?
10 preinitialize
11 pick_boot.run
12 end
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 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
4249ffe2 » jeremy 2007-11-16 Load config/preinitializer.... 26
27 def preinitialize
ab9e4c0e » jeremy 2007-12-17 Ruby 1.9 compatibility. Ref... 28 load(preinitializer_path) if File.exist?(preinitializer_path)
4249ffe2 » jeremy 2007-11-16 Load config/preinitializer.... 29 end
30
31 def preinitializer_path
32 "#{RAILS_ROOT}/config/preinitializer.rb"
33 end
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 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
53e1e50e » dhh 2006-03-31 Specify gem version in envi... 55
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 56 def load_rails_gem
57 if version = self.class.gem_version
bff21727 » jeremy 2007-11-16 RAILS_GEM_VERSION may be se... 58 gem 'rails', version
b98dcdec » jeremy 2007-10-18 Merge [7832] from 1-2-stabl... 59 else
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 60 gem 'rails'
61 end
62 rescue Gem::LoadError => load_error
2bfd6772 » jeremy 2007-10-25 Use instead of STDERR in b... 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.)
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 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
b98dcdec » jeremy 2007-10-18 Merge [7832] from 1-2-stabl... 80 end
53e1e50e » dhh 2006-03-31 Specify gem version in envi... 81
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 82 def load_rubygems
83 require 'rubygems'
53e1e50e » dhh 2006-03-31 Specify gem version in envi... 84
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 85 unless rubygems_version >= '0.9.4'
2bfd6772 » jeremy 2007-10-25 Use instead of STDERR in b... 86 $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 87 exit 1
88 end
89
90 rescue LoadError
2bfd6772 » jeremy 2007-10-25 Use instead of STDERR in b... 91 $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
c077a730 » dhh 2006-04-07 Fixed that boot.rb would se... 92 exit 1
93 end
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 94
95 def parse_gem_version(text)
9ccbb135 » jeremy 2007-12-09 Allow double quotes around ... 96 $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 97 end
98
99 private
100 def read_environment_rb
101 File.read("#{RAILS_ROOT}/config/environment.rb")
102 end
53e1e50e » dhh 2006-03-31 Specify gem version in envi... 103 end
c10a2d24 » seckar 2006-03-31 Teach Rails apps to only lo... 104 end
8dfe5b78 » jeremy 2007-03-06 Windows: include MinGW in R... 105 end
2559feb5 » jeremy 2007-10-22 Refactor and test boot.rb. ... 106
107 # All that for this:
108 Rails.boot!