class Rails::GemBoot

Public Class Methods

gem_version() click to toggle source
# File lib/generator/files/config/boot.rb, line 78
def gem_version
  if defined? RAILS_GEM_VERSION
    RAILS_GEM_VERSION
  elsif ENV.include?('RAILS_GEM_VERSION')
    ENV['RAILS_GEM_VERSION']
  else
    parse_gem_version(read_environment_rb)
  end
end
load_rubygems() click to toggle source
# File lib/generator/files/config/boot.rb, line 88
def load_rubygems
  min_version = '1.3.2'
  require 'rubygems'
  unless rubygems_version >= min_version
    $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
    exit 1
  end

rescue LoadError
  $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
  exit 1
end
parse_gem_version(text) click to toggle source
# File lib/generator/files/config/boot.rb, line 101
def parse_gem_version(text)
  $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
end
rubygems_version() click to toggle source
# File lib/generator/files/config/boot.rb, line 74
def rubygems_version
  Gem::RubyGemsVersion rescue nil
end

Private Class Methods

read_environment_rb() click to toggle source
# File lib/generator/files/config/boot.rb, line 106
def read_environment_rb
  File.read("#{RAILS_ROOT}/config/environment.rb")
end

Public Instance Methods

load_initializer() click to toggle source
# File lib/generator/files/config/boot.rb, line 52
def load_initializer
  self.class.load_rubygems
  load_rails_gem
  require 'initializer'
end
load_rails_gem() click to toggle source
# File lib/generator/files/config/boot.rb, line 58
def load_rails_gem
  if version = self.class.gem_version
    gem 'rails', version
  else
    gem 'rails'
  end
rescue Gem::LoadError => load_error
  if load_error.message =~ /Could not find RubyGem rails/
    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.)
    exit 1
  else
    raise
  end
end