2009年8月22日土曜日

[Rails][CodeReading] Rails::Initializer (2) install_gem_spec_stubs

Initializer.process 内で 2つめに呼ばれる install_gem_spec_stubs メソッド。

def install_gem_spec_stubs
unless Rails.respond_to?(:vendor_rails?)
abort %{Your config/boot.rb is outdated: Run "rake rails:update".}
end

if Rails.vendor_rails?
begin; require "rubygems"; rescue LoadError; return; end

stubs = %w(rails activesupport activerecord actionpack actionmailer activeresource)
stubs.reject! { |s| Gem.loaded_specs.key?(s) }

stubs.each do |stub|
Gem.loaded_specs[stub] = Gem::Specification.new do |s|
s.name = stub
s.version = Rails::VERSION::STRING
s.loaded_from = ""
end
end
end
end


Vendor Rails の場合に、rails, activesupport, activerecord, actionpack, actionmailer, activeresource の stub gem を用意しているようです。gemの仕組みを知らないので詳細はわからない...。

コメントには、
This allows Gem plugins to depend on Rails even when the Gem version of Rails shouldn't be loaded.
とあります。

[Rails][CodeReading] Railsの初期化コードを読む (イントロ&目次)

0 件のコメント:

コメントを投稿