Permalink
Browse files

Add option to list outdated gems.

Adds an options to the gem bundle command called --list-outdated that searches
the gem sources for newer versions of the bundled gems. If there is a newer
version available it will show it in a list.
  • Loading branch information...
1 parent 5a175a3 commit cf9c486c1aeae04921b19782d70cda196df28bfa @Manfred Manfred committed Oct 31, 2009
View
4 lib/bundler/cli.rb
@@ -51,6 +51,10 @@ def list
@environment.list(@options)
end
+ def list_outdated
+ @environment.list_outdated(@options)
+ end
+
def exec
@environment.setup_environment
# w0t?
View
6 lib/bundler/commands/bundle_command.rb
@@ -26,6 +26,10 @@ def initialize
add_option('--list', "List all gems that are part of the active bundle") do
options[:list] = true
end
+
+ add_option('--list-outdated', "List all outdated gems that are part of the active bundle") do
+ options[:list_outdated] = true
+ end
add_option('-b', '--build-options OPTION_FILE', "Specify a path to a yml file with build options for binary gems") do |option_file, options|
if File.exist?(option_file)
@@ -53,6 +57,8 @@ def execute
Bundler::CLI.run(:prune, options)
elsif options[:list]
Bundler::CLI.run(:list, options)
+ elsif options[:list_outdated]
+ Bundler::CLI.run(:list_outdated, options)
else
Bundler::CLI.run(:bundle, options)
end
View
12 lib/bundler/environment.rb
@@ -101,6 +101,18 @@ def list(options = {})
end
end
+ def list_outdated(options={})
+ outdated_gems = repository.outdated_gems
+ if outdated_gems.empty?
+ Bundler.logger.info "All gems are up to date."
+ else
+ Bundler.logger.info "Outdated gems:"
+ outdated_gems.each do |name|
+ Bundler.logger.info " * #{name}"
+ end
+ end
+ end
+
def setup_environment
unless system_gems
ENV["GEM_HOME"] = gem_path
View
4 lib/bundler/repository.rb
@@ -76,6 +76,10 @@ def gems
source_index.gems.values
end
+ def outdated_gems(sources)
+ source_index.outdated.sort
+ end
+
def source_index
index = Gem::SourceIndex.from_gems_in(@path.join("specifications"))
index.each { |n, spec| spec.loaded_from = @path.join("specifications", "#{spec.full_name}.gemspec") }
View
41 spec/bundler/cli_spec.rb
@@ -434,4 +434,45 @@
end
end
end
+
+ describe "listing outdated gems" do
+ it "shows a message when there are no outdated gems" do
+ m = build_manifest <<-Gemfile
+ clear_sources
+ Gemfile
+ m.install
+
+ Dir.chdir(bundled_app) do
+ @output = gem_command :bundle, "--list-outdated"
+ end
+
+ @output.should =~ /All gems are up to date/
+ end
+
+ it "shows all the outdated gems" do
+ m = build_manifest <<-Gemfile
+ clear_sources
+ source "file://#{gem_repo1}"
+ source "file://#{gem_repo2}"
+ gem "rack", "0.9.1"
+ gem "rails"
+ Gemfile
+ m.install
+
+ Dir.chdir(bundled_app) do
+ @output = gem_command :bundle, "--list-outdated"
+ end
+
+ [ "Outdated gems:",
+ " * actionmailer",
+ " * actionpack",
+ " * activerecord",
+ " * activeresource",
+ " * activesupport",
+ " * rack",
+ " * rails"].each do |message|
+ @output.should =~ /^#{Regexp.escape(message)}$/
+ end
+ end
+ end
end

0 comments on commit cf9c486

Please sign in to comment.