boot.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:3k
源码类别:

Ajax

开发平台:

Others

  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.         require 'rubygems'
  72.         min_version = '1.3.1'
  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_VERSIONs*=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. # All that for this:
  92. Rails.boot!