Basis of rails-driven app for local business
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

109 lines
2.7 KiB

  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. end
  39. end
  40. class GemBoot < Boot
  41. def load_initializer
  42. self.class.load_rubygems
  43. load_rails_gem
  44. require 'initializer'
  45. end
  46. def load_rails_gem
  47. if version = self.class.gem_version
  48. gem 'rails', version
  49. else
  50. gem 'rails'
  51. end
  52. rescue Gem::LoadError => load_error
  53. $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.)
  54. exit 1
  55. end
  56. class << self
  57. def rubygems_version
  58. Gem::RubyGemsVersion rescue nil
  59. end
  60. def gem_version
  61. if defined? RAILS_GEM_VERSION
  62. RAILS_GEM_VERSION
  63. elsif ENV.include?('RAILS_GEM_VERSION')
  64. ENV['RAILS_GEM_VERSION']
  65. else
  66. parse_gem_version(read_environment_rb)
  67. end
  68. end
  69. def load_rubygems
  70. require 'rubygems'
  71. min_version = '1.3.1'
  72. unless rubygems_version >= min_version
  73. $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
  74. exit 1
  75. end
  76. rescue LoadError
  77. $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
  78. exit 1
  79. end
  80. def parse_gem_version(text)
  81. $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
  82. end
  83. private
  84. def read_environment_rb
  85. File.read("#{RAILS_ROOT}/config/environment.rb")
  86. end
  87. end
  88. end
  89. end
  90. # All that for this:
  91. Rails.boot!