unicorn 4.3.1 - shutdown() fixes
[unicorn.git] / test / rails / app-2.2.2 / config / boot.rb
blobe357f0a61685f3d4cd693d86609332019c062154
1 # -*- encoding: binary -*-
3 # Don't change this file!
4 # Configure your app in config/environment.rb and config/environments/*.rb
6 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
17     def booted?
18       defined? Rails::Initializer
19     end
21     def pick_boot
22       (vendor_rails? ? VendorBoot : GemBoot).new
23     end
25     def vendor_rails?
26       File.exist?("#{RAILS_ROOT}/vendor/rails")
27     end
29     def preinitialize
30       load(preinitializer_path) if File.exist?(preinitializer_path)
31     end
33     def preinitializer_path
34       "#{RAILS_ROOT}/config/preinitializer.rb"
35     end
36   end
38   class Boot
39     def run
40       load_initializer
41       Rails::Initializer.run(:set_load_path)
42     end
43   end
45   class VendorBoot < Boot
46     def load_initializer
47       require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
48       Rails::Initializer.run(:install_gem_spec_stubs)
49     end
50   end
52   class GemBoot < Boot
53     def load_initializer
54       self.class.load_rubygems
55       load_rails_gem
56       require 'initializer'
57     end
59     def load_rails_gem
60       if version = self.class.gem_version
61         gem 'rails', version
62       else
63         gem 'rails'
64       end
65     rescue Gem::LoadError => load_error
66       $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.)
67       exit 1
68     end
70     class << self
71       def rubygems_version
72         Gem::RubyGemsVersion rescue nil
73       end
75       def gem_version
76         if defined? RAILS_GEM_VERSION
77           RAILS_GEM_VERSION
78         elsif ENV.include?('RAILS_GEM_VERSION')
79           ENV['RAILS_GEM_VERSION']
80         else
81           parse_gem_version(read_environment_rb)
82         end
83       end
85       def load_rubygems
86         require 'rubygems'
87         min_version = '1.3.1'
88         unless rubygems_version >= min_version
89           $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
90           exit 1
91         end
93       rescue LoadError
94         $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
95         exit 1
96       end
98       def parse_gem_version(text)
99         $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
100       end
102       private
103         def read_environment_rb
104           File.read("#{RAILS_ROOT}/config/environment.rb")
105         end
106     end
107   end
110 # All that for this:
111 Rails.boot!