annotate .svn/pristine/da/da30f481208d9237a3f64922ab33dc92a83a4114.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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