Skip to content

Commit

Permalink
Consolidate error messages for missing gems, and skip them when runni…
Browse files Browse the repository at this point in the history
…ng rake gems:* tasks. [rick]
  • Loading branch information
technoweenie committed May 31, 2008
1 parent 2506e5c commit d5bcff1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
2 changes: 2 additions & 0 deletions railties/CHANGELOG
@@ -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)*
Expand Down
43 changes: 31 additions & 12 deletions railties/lib/initializer.rb
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion railties/lib/rails/gem_dependency.rb
Expand Up @@ -36,7 +36,6 @@ def add_load_paths
end
@load_paths_added = true
rescue Gem::LoadError
puts $!.to_s
end

def dependencies
Expand Down
12 changes: 9 additions & 3 deletions railties/lib/tasks/gems.rake
@@ -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}"
Expand All @@ -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')
Expand All @@ -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|
Expand Down

0 comments on commit d5bcff1

Please sign in to comment.