Permalink
Browse files

Consolidate error messages for missing gems, and skip them when runni…

…ng rake gems:* tasks. [rick]
  • Loading branch information...
1 parent 2506e5c commit d5bcff172b6253684cf5cc3345a3d390096ba957 @technoweenie technoweenie committed May 31, 2008
Showing with 42 additions and 16 deletions.
  1. +2 −0 railties/CHANGELOG
  2. +31 −12 railties/lib/initializer.rb
  3. +0 −1 railties/lib/rails/gem_dependency.rb
  4. +9 −3 railties/lib/tasks/gems.rake
View
@@ -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 @@ def process
# 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 @@ def process
initialize_routing
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
+
load_observers
end
@@ -241,7 +243,24 @@ def add_gem_load_paths
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 @@ def load_environment
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 @@ def initialize_framework_settings
# 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 @@ def add_load_paths
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|

0 comments on commit d5bcff1

Please sign in to comment.