【问题标题】:Why is bundler loading all my gems instead of specific ones为什么捆绑器会加载我所有的宝石而不是特定的宝石
【发布时间】:2014-06-04 18:19:00
【问题描述】:

我有一个 Sinatra 应用程序,我正在尝试在我的 Gemfile 中使用组,以便仅加载指定的 gem。但是,当我将加载限制为仅一个组捆绑器时,仍然会加载文件中的每个 gem。这是我的 Gemfile:

source 'https://rubygems.org'

group :one do
  gem 'sinatra'
end

group :two do 
  gem 'bitly'
end

这是我的申请:

require 'bundler/setup'
Bundler.require(:one)

class App < Sinatra::Base

  configure do
    puts Gem.loaded_specs.keys.sort.join("\t")
  end

  get '/foo' do
  end

end

我可以清楚地看到应用程序启动时加载的 Bitly gem。我做错了什么?

【问题讨论】:

标签: ruby bundler


【解决方案1】:

使用

require 'bundler'

而不是

require 'bundler/setup'

最后一个自动加载 Gemfile 中的所有 gem:Why do you need "require 'bundler/setup'"?

【讨论】:

    猜你喜欢
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 2013-04-19
    相关资源
    最近更新 更多