|
Revision 8365, 2.6 kB
(checked in by bitsweat, 1 year ago)
|
Ruby 1.9 compat: File.exists\? -> File.exist\? en masse. References #1689 [Pratik Naik]
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) |
|---|
| 5 |
|
|---|
| 6 |
module Rails |
|---|
| 7 |
class << self |
|---|
| 8 |
def boot! |
|---|
| 9 |
unless booted? |
|---|
| 10 |
preinitialize |
|---|
| 11 |
pick_boot.run |
|---|
| 12 |
end |
|---|
| 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 |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
def preinitialize |
|---|
| 29 |
load(preinitializer_path) if File.exists?(preinitializer_path) |
|---|
| 30 |
end |
|---|
| 31 |
|
|---|
| 32 |
def preinitializer_path |
|---|
| 33 |
"#{RAILS_ROOT}/config/preinitializer.rb" |
|---|
| 34 |
end |
|---|
| 35 |
end |
|---|
| 36 |
|
|---|
| 37 |
class Boot |
|---|
| 38 |
def run |
|---|
| 39 |
load_initializer |
|---|
| 40 |
Rails::Initializer.run(:set_load_path) |
|---|
| 41 |
end |
|---|
| 42 |
end |
|---|
| 43 |
|
|---|
| 44 |
class VendorBoot < Boot |
|---|
| 45 |
def load_initializer |
|---|
| 46 |
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" |
|---|
| 47 |
end |
|---|
| 48 |
end |
|---|
| 49 |
|
|---|
| 50 |
class GemBoot < Boot |
|---|
| 51 |
def load_initializer |
|---|
| 52 |
self.class.load_rubygems |
|---|
| 53 |
load_rails_gem |
|---|
| 54 |
require 'initializer' |
|---|
| 55 |
end |
|---|
| 56 |
|
|---|
| 57 |
def load_rails_gem |
|---|
| 58 |
if version = self.class.gem_version |
|---|
| 59 |
gem 'rails', version |
|---|
| 60 |
else |
|---|
| 61 |
gem 'rails' |
|---|
| 62 |
end |
|---|
| 63 |
rescue Gem::LoadError => load_error |
|---|
| 64 |
$stderr.puts %(Missing the Rails |
|---|
| 65 |
exit 1 |
|---|
| 66 |
end |
|---|
| 67 |
|
|---|
| 68 |
class << self |
|---|
| 69 |
def rubygems_version |
|---|
| 70 |
Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion |
|---|
| 71 |
end |
|---|
| 72 |
|
|---|
| 73 |
def gem_version |
|---|
| 74 |
if defined? RAILS_GEM_VERSION |
|---|
| 75 |
RAILS_GEM_VERSION |
|---|
| 76 |
elsif ENV.include?('RAILS_GEM_VERSION') |
|---|
| 77 |
ENV['RAILS_GEM_VERSION'] |
|---|
| 78 |
else |
|---|
| 79 |
parse_gem_version(read_environment_rb) |
|---|
| 80 |
end |
|---|
| 81 |
end |
|---|
| 82 |
|
|---|
| 83 |
def load_rubygems |
|---|
| 84 |
require 'rubygems' |
|---|
| 85 |
|
|---|
| 86 |
unless rubygems_version >= '0.9.4' |
|---|
| 87 |
$stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have |
|---|
| 88 |
exit 1 |
|---|
| 89 |
end |
|---|
| 90 |
|
|---|
| 91 |
rescue LoadError |
|---|
| 92 |
$stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org) |
|---|
| 93 |
exit 1 |
|---|
| 94 |
end |
|---|
| 95 |
|
|---|
| 96 |
def parse_gem_version(text) |
|---|
| 97 |
$1 if text =~ /^[^ |
|---|
| 98 |
end |
|---|
| 99 |
|
|---|
| 100 |
private |
|---|
| 101 |
def read_environment_rb |
|---|
| 102 |
File.read("#{RAILS_ROOT}/config/environment.rb") |
|---|
| 103 |
end |
|---|
| 104 |
end |
|---|
| 105 |
end |
|---|
| 106 |
end |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
Rails.boot! |
|---|