ruby - bundle 安装从错误的目录运行

标签 ruby gem rvm bundler thor

我正在为一些内部项目构建一个简单的基于 thor 的生成器,但似乎无法从正确的目录运行 bundle install

当我运行新的 [APP_NAME] 函数时,它应该创建目录和文件,然后运行 ​​bundle install 来安装应用程序所需的 gem。 p>

生成器函数的来源:

def create
  puts "Creating application #{name}"

  directory 'application', "#{name}"

  Dir.chdir("#{Dir.pwd}/#{name}") do
    puts `bundle install`
  end
end

运行调用此创建方法的命令的控制台输出:

$ bundle exec bin/my_gem new test_app
Creating application test_app
      create  test_app
      create  test_app/Gemfile
      create  test_app/Guardfile
      create  test_app/README.md
      create  test_app/app/controllers
      create  test_app/app/helpers
      create  test_app/app/models
      create  test_app/app/views
Using thor (0.14.6) 
Using my_gem (0.0.1) 
Using bundler (1.1.3) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

如您所见,它正在运行 bundle install 但它在我当前的目录中运行 (thor, bundler, my_gem),相对于 test_app 目录(guardguard-coffeescriptguard-less,以及其他)。

运行其他命令,如 lspwd 给出预期的结果:

Gemfile
Guardfile
README.md
app

/Users/davidlumley/Development/Gems/my_gem/test_app

不确定这是否有任何区别,但我使用 RVM 来管理我的 ruby 。

最佳答案

听起来您的应用已经在使用 bundler ,并且您遇到了 bundler 内部 bundler 问题。试试这个:

Bundler.with_clean_env do
  puts `bundle install`
end

我猜你的外部打包器将 BUNDLE_GEMFILE 环境变量设置为你应用的 Gemfile,然后你的内部打包器最终继承了它。

关于ruby - bundle 安装从错误的目录运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10185552/

相关文章:

ruby - 在 Ruby 中构建交集矩阵

ruby - 当前面有特定字符串时,如何找到所有出现的字符序列?

ruby - 警告! PATH 没有设置好,一般是 shell 初始化文件引起的

ruby - 构建后 Gem 中缺少文件

ios - CocoaPods 安装失败(无法解析依赖)

rvm - 运行 'rvm get head' 时,我得到 : Unrecognized command line argument: 'get' ( see: 'rvm usage' )". 我该如何解决?

ruby-on-rails - 同一类的 Rails 多个 belongs_to

ruby-on-rails - 解析 gemfile 并获取 rails 项目中使用的所有 gem

ruby - rvm gemset 复制错误

ruby - 无法为此处文档创建临时文件,使用 rvm 安装 ruby​​ 1.9.2