diff options
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/lib/initializer.rb | 43 | ||||
-rw-r--r-- | railties/lib/rails/gem_dependency.rb | 1 | ||||
-rw-r--r-- | railties/lib/tasks/gems.rake | 12 |
4 files changed, 42 insertions, 16 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index c765dedae5..7f1c6ad747 100644 --- a/railties/CHANGELOG +++ b/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)* diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 8f963cb4a5..ca63fa734b 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -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 diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index 22ee0e3601..0e39f6fd0a 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -36,7 +36,6 @@ module Rails end @load_paths_added = true rescue Gem::LoadError - puts $!.to_s end def dependencies diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake index c18fea2d60..0321e60e0f 100644 --- a/railties/lib/tasks/gems.rake +++ b/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}" @@ -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| |