为什么Bundler安装错误的gem版本?

时间:2013-01-29 23:34:23

标签: ruby bundler

我正在尝试使用Bundler安装composite_primary_keys gem的自定义版本,该版本根据2.2.2版本进行了一些我们需要的更改。我们的gem版本是2.2.2.0并托管在我们的内部gem服务器上(这个4位版本控制方案仅存在于我们的内部gem服务器上)。应用程序要求是我们在jruby-1.6.7(RUBY_VERSION = 1.8.7),RubyGems版本(gem -v)1.3.6,以及Bundler的最新稳定版本,1.2.3

无论如何,我的Gemfile看起来像这样:

source 'http://rubygems.org'
source 'http://gems.internal'

gem 'composite_primary_keys', '2.2.2.0'
gem 'hoe',                    '1.8.3'

执行bundle输出:

$ bundle
Fetching gem metadata from http://rubygems.org/........
Fetching gem metadata from http://gems.internal/...
Installing rake (10.0.3) 
Installing i18n (0.6.1) 
Installing multi_json (1.5.0) 
Installing activesupport (3.2.11) 
Installing builder (3.0.4) 
Installing activemodel (3.2.11) 
Installing arel (3.0.2) 
Installing tzinfo (0.3.35) 
Installing activerecord (3.2.11) 
Installing json_pure (1.7.6) 
Installing rubyforge (2.0.4) 
Installing hoe (1.8.3) 
Installing composite_primary_keys (2.2.2) 
Using bundler (1.2.3) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

如您所见,composite_primary_keys 2.2.2实际上已安装,而不是2.2.2.0。这是生成的Gemfile.lock:

GEM
  remote: http://rubygems.org/
  remote: http://gems.internal/
  specs:
    activemodel (3.2.11)
      activesupport (= 3.2.11)
      builder (~> 3.0.0)
    activerecord (3.2.11)
      activemodel (= 3.2.11)
      activesupport (= 3.2.11)
      arel (~> 3.0.2)
      tzinfo (~> 0.3.29)
    activesupport (3.2.11)
      i18n (~> 0.6)
      multi_json (~> 1.0)
    arel (3.0.2)
    builder (3.0.4)
    composite_primary_keys (2.2.2)
      activerecord (>= 2.2.0)
      hoe (>= 1.8.3)
    hoe (1.8.3)
      rake (>= 0.8.3)
      rubyforge (>= 1.0.2)
    i18n (0.6.1)
    json_pure (1.7.6)
    multi_json (1.5.0)
    rake (10.0.3)
    rubyforge (2.0.4)
      json_pure (>= 1.1.7)
    tzinfo (0.3.35)

PLATFORMS
  java

DEPENDENCIES
  composite_primary_keys (= 2.2.2.0)
  hoe (= 1.8.3)

现在,如果我卸载composite_primary_keys并手动安装我的版本:

$ gem uninstall composite_primary_keys
Successfully uninstalled composite_primary_keys-2.2.2
$ gem install composite_primary_keys -v 2.2.2.0
Successfully installed composite_primary_keys-2.2.2.0
1 gem installed
Installing ri documentation for composite_primary_keys-2.2.2.0...
Installing RDoc documentation for composite_primary_keys-2.2.2.0...

然后执行bundle

$ bundle        
Using rake (10.0.3) 
Using i18n (0.6.1) 
Using multi_json (1.5.0) 
Using activesupport (3.2.11) 
Using builder (3.0.4) 
Using activemodel (3.2.11) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.11) 
Using composite_primary_keys (2.2.2.0) 
Using json_pure (1.7.6) 
Using rubyforge (2.0.4) 
Using hoe (1.8.3) 
Using bundler (1.2.3) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

它保留了我的自定义宝石。此时运行捆绑包更新会更新Gemfile.lock

$ bundle update composite_primary_keys
Fetching gem metadata from http://rubygems.org/........
Fetching gem metadata from http://gems.internal/...
Using rake (10.0.3) 
Using i18n (0.6.1) 
Using multi_json (1.5.0) 
Using activesupport (3.2.11) 
Using builder (3.0.4) 
Using activemodel (3.2.11) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.11) 
Using composite_primary_keys (2.2.2.0) 
Using json_pure (1.7.6) 
Using rubyforge (2.0.4) 
Using hoe (1.8.3) 
Using bundler (1.2.3) 
Your bundle is updated! Use `bundle show [gemname]` to see where a bundled gem is installed.

Gemfile.lock现在看起来像这样:

GEM
  remote: http://rubygems.org/
  remote: http://gems.internal/
  specs:
    activemodel (3.2.11)
      activesupport (= 3.2.11)
      builder (~> 3.0.0)
    activerecord (3.2.11)
      activemodel (= 3.2.11)
      activesupport (= 3.2.11)
      arel (~> 3.0.2)
      tzinfo (~> 0.3.29)
    activesupport (3.2.11)
      i18n (~> 0.6)
      multi_json (~> 1.0)
    arel (3.0.2)
    builder (3.0.4)
    composite_primary_keys (2.2.2.0)
      activerecord (>= 2.2.0)
    hoe (1.8.3)
      rake (>= 0.8.3)
      rubyforge (>= 1.0.2)
    i18n (0.6.1)
    json_pure (1.7.6)
    multi_json (1.5.0)
    rake (10.0.3)
    rubyforge (2.0.4)
      json_pure (>= 1.1.7)
    tzinfo (0.3.35)

PLATFORMS
  java

DEPENDENCIES
  composite_primary_keys (= 2.2.2.0)
  hoe (= 1.8.3)

我的猜测

我的怀疑是Bundler以某种方式依赖于RubyGems如何实现< =>操作者...

require 'rubygems'
Gem::Version.new('2.2.2') <=> Gem::Version.new('2.2.2.0') # => 0
Gem::Version.new('2.2.2') == Gem::Version.new('2.2.2.0') # => true

任何人都可以确认吗?这是预期的行为吗?如果版本号丢失了一个数字,这对于避免次要版本号为0是一个很好的论据吗? e.g。

Gem::Version.new('2') == Gem::Version.new('2.0.0.0.0.0.0.0.0') # => true

1 个答案:

答案 0 :(得分:0)

虽然这不能直接回答你的问题。我在过去遇到了类似的问题,最终使自定义gem成为另一个gem的扩展。即要修补“my-awesome-gem”中的功能,你会称之为“my-awesome-gem-custom”或类似的东西。相信我,你要走的路线充满了依赖性的噩梦。 :)

但需要注意的是注意扩展gem的require Custom Gem Naming的差异,因为它们略有不同。 “require / x / y / z”与“requre x_y_z”。这样做应该允许您使用Ruby的开放类来根据需要分层或覆盖功能。