merged cont.
[opensuse:yast-rest-service.git] / webyast / config / boot.rb
1 # Source: generated by rails
2 # Don't change this file!
3 # Configure your app in config/environment.rb and config/environments/*.rb
4
5 RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
6
7 module Rails
8   class << self
9     def boot!
10       unless booted?
11         preinitialize
12         pick_boot.run
13       end
14     end
15
16     def booted?
17       defined? Rails::Initializer
18     end
19
20     def pick_boot
21       (vendor_rails? ? VendorBoot : GemBoot).new
22     end
23
24     def vendor_rails?
25       File.exist?("#{RAILS_ROOT}/vendor/rails")
26     end
27
28     def preinitialize
29       load(preinitializer_path) if File.exist?(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       Rails::Initializer.run(:install_gem_spec_stubs)
48       Rails::GemDependency.add_frozen_gem_path
49     end
50   end
51
52   class GemBoot < Boot
53     def load_initializer
54       self.class.load_rubygems
55       load_rails_gem
56       require 'initializer'
57     end
58
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.) # RORSCAN_ITL
67       exit 1
68     end
69
70     class << self
71       def rubygems_version
72         Gem::RubyGemsVersion rescue nil
73       end
74
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
84
85       def load_rubygems
86         require 'rubygems'
87         min_version = '1.2.0'
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.) # RORSCAN_ITL
90           exit 1
91         end
92
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
97
98       def parse_gem_version(text)
99         $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
100       end
101
102       private
103         def read_environment_rb
104           File.read("#{RAILS_ROOT}/config/environment.rb")
105         end
106     end
107   end
108 end
109
110 # All that for this:
111 Rails.boot!