Programmatically determine gem's path using bundler

前端 未结 4 1410
借酒劲吻你
借酒劲吻你 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:37

    Yup, cli.rb is the best way to look at. However you anyway have to find a spec's name.

    I can give you a starting point, but you have to come with some solution on how to optimize to your case:

    
        GemSearcher = Gem::GemPathSearcher.new
        Init = GemSearcher.init_gemspecs()
        GemSearcher.lib_dirs_for(Init[0])
    
    

    Unfortunately this solution provides nameless search as all Gems are in an array instead of hash, but if you want you can hack GemPathSearcher, I think that would be useful in the future.

提交回复
热议问题