Friday, August 30 2013
I am back to working on the issue where when you run bundle oudated gem-not-in-your-Gemfile it returns that your bundle isup to date. In this example the serv gem is not in the Gemfile.
$ bundle outdated serv
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Your bundle is up to date!
I was looking at the bundler/lib/bundler/cli.rb files. In the bundle desc inject section I found a def not_found_message that looks similar to what I want to do; identify a missing gem.
def not_found_message(missing_gem_name, alternatives) message = "Could not find gem '#{missing_gem_name}'."
# This is called as the result of a GemNotFound, let's see if
# there's any similarly named ones we can propose instead
alternate_names = alternatives.map { |a| a.respond_to?(:name) ? a.name : a }
suggestions = SimilarityDetector.new(alternate_names).similar_word_list(missing_gem_name)
message += "\nDid you mean #{suggestions}?" if suggestions
message
end
I ran `bundle inject
$ bundle inject blurg 1.0.0
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Could not find gem 'blurg (= 1.0.0) ruby' in the gems available on this machine.
This seemed closer to the error I want to see when I run bundle outdated non-existing-gem
so I decide to check out a few more command to see if I could find one with a message I'd like to see.
I ran bundle show serv (The serv gem is NOT in the Gemafile.)
$ bundle show serv
Could not find gem 'serv'.
Did you mean sdoc?
This is even closer to the error I want to see. So I checked out the code in the desc show section of the bundler/lib/bundler/cli.rb file.
desc "show [GEM]", "Shows all gems that are part of the bundle, or the path to a given gem"
long_desc <<-D
Show lists the names and versions of all gems that are required by your Gemfile.
Calling show with [GEM] will list the exact location of that gem on your machine.
D
method_option "paths", :type => :boolean,
:banner => "List the paths of all gems that are required by your Gemfile."
def show(gem_name = nil)
Bundler.ui.silence do
Bundler.definition.validate_ruby!
Bundler.load.lock
end
if gem_name
if gem_name == "bundler"
path = File.expand_path("../../..", __FILE__)
else
spec = select_spec(gem_name, :regex_match)
return unless spec
path = spec.full_gem_path
if !File.directory?(path)
Bundler.ui.warn "The gem #{gem_name} has been deleted. It was installed at:"
end
end
return Bundler.ui.info(path)
end
if options[:paths]
Bundler.load.specs.sort_by { |s| s.name }.map do |s|
Bundler.ui.info s.full_gem_path
end
else
Bundler.ui.info "Gems included by the bundle:"
Bundler.load.specs.sort_by { |s| s.name }.each do |s|
Bundler.ui.info " * #{s.name} (#{s.version}#{s.git_version})"
end
end
end
I am now working on a path that will lead me to the answer...