You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

boot.rb 3.1KB

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