Query dependency list from within a rails app

2019-06-11 22:34发布

From a running rails app is there a way to enumerate the list of dependencies for the application? Assume I don't have access to the Gemfile or Gemfile.lock files.

I need the gem name and the version number so something like:

[["actionmailer" "3.1.3"]
 ["coffeescript" "2.0.2"]]

1条回答
Summer. ? 凉城
2楼-- · 2019-06-11 23:13

Assuming bundler, which you should use, you can access it like this:

Bundler.environment.current_dependencies
#=> [<Bundler::Dependency type=:development name="minitest" requirements=">= 2.11.0">,
    <Bundler::Dependency type=:development name="rspec-expectations" requirements=">= 2.7.0">,
    <Bundler::Dependency type=:development name="mocha" requirements=">= 0.10.0">,
    <Bundler::Dependency type=:development name="cucumber" requirements=">= 1.1.4">]
查看更多
登录 后发表回答