Week 7 Day 34

It's Optimize Friday


Jen's Friday

I am back to working on the issue where when you run bundle oudated gem-not-in-your-Gemfile it returns that your bundle is up 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

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 Gemfile.)

$ 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.
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

  if gem_name
    if gem_name == "bundler"
      path = File.expand_path("../../..", __FILE__)
      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:"
    return Bundler.ui.info(path)

  if options[:paths]
    Bundler.load.specs.sort_by { |s| s.name }.map do |s|
      Bundler.ui.info s.full_gem_path
    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})"

I am now working on a path that will lead me to the answer…

Joyce's Friday

Started looking at another bundler feature/issue. The feature I am looking to add is when you bundle update, it shows the old version of the gem being updated. I started a rspec test for it.

I received feedback and suggestions for my first addition/fix to the Bundler repo. I made improvements to it based on the comment I received. I made a method to store Bundler.which(“git”) in an instance variable inside bundler.rb. According to mentor Andre, we store it in an instance variable so we only have to look for git once. Instead of having to keep looking for git again and again repeatedly. This technique is called “"memoization."


raise GitError, “Git is not installed!” if !Bundler.which(“git”)


raise GitError, "Git is not installed!" if !Bundler.git_present?