mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Consolidate error messages for missing gems, and skip them when running rake gems:* tasks. [rick]
This commit is contained in:
parent
2506e5c9a7
commit
d5bcff172b
4 changed files with 42 additions and 16 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Consolidate error messages for missing gems, and skip them when running rake gems:* tasks. [rick]
|
||||
|
||||
* Use a system command to install gems, since GemRunner exits the ruby process. #210 [Tim Morgan]
|
||||
|
||||
*2.1.0 RC1 (May 11th, 2008)*
|
||||
|
|
|
@ -140,7 +140,8 @@ module Rails
|
|||
# pick up any gems that plugins depend on
|
||||
add_gem_load_paths
|
||||
load_gems
|
||||
|
||||
check_gem_dependencies
|
||||
|
||||
load_application_initializers
|
||||
|
||||
# the framework is now fully initialized
|
||||
|
@ -153,6 +154,7 @@ module Rails
|
|||
initialize_routing
|
||||
|
||||
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
|
||||
|
||||
load_observers
|
||||
end
|
||||
|
||||
|
@ -241,7 +243,24 @@ module Rails
|
|||
end
|
||||
|
||||
def load_gems
|
||||
@configuration.gems.each &:load
|
||||
@configuration.gems.each(&:load)
|
||||
end
|
||||
|
||||
def check_gem_dependencies
|
||||
unloaded_gems = @configuration.gems.reject { |g| g.loaded? }
|
||||
if unloaded_gems.size > 0
|
||||
@gems_dependencies_loaded = false
|
||||
# don't print if the gems rake tasks are being run
|
||||
unless $rails_gem_installer
|
||||
puts %{These gems that this application depends on are missing:}
|
||||
unloaded_gems.each do |gem|
|
||||
puts " - #{gem.name}"
|
||||
end
|
||||
puts %{Run "rake gems:install" to install them.}
|
||||
end
|
||||
else
|
||||
@gems_dependencies_loaded = true
|
||||
end
|
||||
end
|
||||
|
||||
# Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
|
||||
|
@ -287,12 +306,8 @@ module Rails
|
|||
end
|
||||
|
||||
def load_observers
|
||||
if configuration.frameworks.include?(:active_record)
|
||||
if @configuration.gems.any? { |g| !g.loaded? }
|
||||
puts %{Unable to instantiate observers, some gems that this application depends on are missing. Run "rake gems:install"}
|
||||
else
|
||||
ActiveRecord::Base.instantiate_observers
|
||||
end
|
||||
if @gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
|
||||
ActiveRecord::Base.instantiate_observers
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -447,14 +462,18 @@ module Rails
|
|||
|
||||
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
|
||||
def after_initialize
|
||||
configuration.after_initialize_blocks.each do |block|
|
||||
block.call
|
||||
if @gems_dependencies_loaded
|
||||
configuration.after_initialize_blocks.each do |block|
|
||||
block.call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def load_application_initializers
|
||||
Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
|
||||
load(initializer)
|
||||
if @gems_dependencies_loaded
|
||||
Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
|
||||
load(initializer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ module Rails
|
|||
end
|
||||
@load_paths_added = true
|
||||
rescue Gem::LoadError
|
||||
puts $!.to_s
|
||||
end
|
||||
|
||||
def dependencies
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
desc "List the gems that this rails application depends on"
|
||||
task :gems => :environment do
|
||||
task :gems => 'gems:base' do
|
||||
Rails.configuration.gems.each do |gem|
|
||||
code = gem.loaded? ? (gem.frozen? ? "F" : "I") : " "
|
||||
puts "[#{code}] #{gem.name} #{gem.requirement.to_s}"
|
||||
|
@ -10,8 +10,14 @@ task :gems => :environment do
|
|||
end
|
||||
|
||||
namespace :gems do
|
||||
task :base do
|
||||
$rails_gem_installer = true
|
||||
Rake::Task[:environment].invoke
|
||||
end
|
||||
|
||||
desc "Build any native extensions for unpacked gems"
|
||||
task :build do
|
||||
$rails_gem_installer = true
|
||||
require 'rails/gem_builder'
|
||||
Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*')].each do |gem_dir|
|
||||
spec_file = File.join(gem_dir, '.specification')
|
||||
|
@ -24,14 +30,14 @@ namespace :gems do
|
|||
end
|
||||
|
||||
desc "Installs all required gems for this application."
|
||||
task :install => :environment do
|
||||
task :install => :base do
|
||||
require 'rubygems'
|
||||
require 'rubygems/gem_runner'
|
||||
Rails.configuration.gems.each { |gem| gem.install unless gem.loaded? }
|
||||
end
|
||||
|
||||
desc "Unpacks the specified gem into vendor/gems."
|
||||
task :unpack => :environment do
|
||||
task :unpack => :base do
|
||||
require 'rubygems'
|
||||
require 'rubygems/gem_runner'
|
||||
Rails.configuration.gems.each do |gem|
|
||||
|
|
Loading…
Reference in a new issue