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.0KB

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