Programmatically determine gem's path using bundler

前端 未结 4 1421
借酒劲吻你
借酒劲吻你 2021-02-13 02:37

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?<

4条回答
  •  青春惊慌失措
    2021-02-13 03:19

    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
    

提交回复
热议问题