简体   繁体   English

如何测试Ruby脚本是否通过Bundler运行

[英]How to test if a Ruby script is running via Bundler

在Ruby脚本中,有没有办法测试当前进程是否已经通过Bundler启动 - 即通过bundle exec或binstub?

You could check defined?(Bundler) , but that will also be present if you require 'bundler' without having run bundle exec . 您可以检查已defined?(Bundler) ,但如果您require 'bundler'而没有运行bundle exec ,那么它也会出现。

When you run inside bundle exec , there are a few ENV variables present that aren't otherwise. 当你在bundle exec运行时,会出现一些ENV变量,否则就不存在。 Notably, BUNDLE_GEMFILE and BUNDLE_BIN_PATH . 值得注意的是, BUNDLE_GEMFILEBUNDLE_BIN_PATH

There are some more details in the Environment Modifications section of the bundle exec docs . 捆绑exec文档Environment Modifications部分中有更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM