Programmatically determine gem's path using bundler

bundler, ruby

Solution

Have a look at how they do it in cli.rb

def locate_gem(name)
  spec = Bundler.load.specs.find{|s| s.name == name }
  raise GemNotFound, "Could not find gem '#{name}' in the current bundle." unless spec
  if spec.name == 'bundler'
    return File.expand_path('../../../', __FILE__)
  end
  spec.full_gem_path
end

Problem

I know you can do ``` bundle show gem_name ``` to show the path of some gem. How do you do that from within the code using the Bundler object?

Original source