使用从Rake安装到系统的Gem

时间:2014-09-14 09:38:51

标签: ruby gem rake bundler command-line-interface

我有一个Rake任务,它使用名为fontcustom的gem的CLI。它已经很长时间没有收到更新,其依赖项与我的捆绑包中的其他Gems不兼容,因此我无法将其添加到Gemfile

我的系统上安装了正确的版本,但我无法看到如何让Rake任务使用系统版本。如果fontcustom中没有Gemfile,则运行引用它的rake任务会给我一个错误:

  

fontcustom不是捆绑包的一部分。将其添加到Gemfile。   (GEM :: LoadError)

我可以明确告诉rake任务使用fontcustom的系统版本吗?

列出宝石:

$ gem list fontcustom
# fontcustom (1.3.3)

任务:

namespace :font do
  desc "Compile custom icon font"
  task :compile do
    Dir.chdir('resources/graphics/fonts/custom') do
       system 'fontcustom compile' # fontcustom is not part of the bundle.
       # `fontcustom compile` # fontcustom is not part of the bundle.
       # %x(fontcustom compile) # fontcustom compile: command not found
    end
  end
end

1 个答案:

答案 0 :(得分:3)

你可以使用Bundler.with_clean_env,它在重置各种Bundler特定的环境变量后执行一个块:

Bundler.with_clean_env { system 'fontcustom compile' }

或稍微简洁clean_system(使用with_clean_env):

Bundler.clean_system 'fontcustom compile'
相关问题