1

composite_primary_keysバージョンに基づいて必要な変更を加えた Bundler を使用して、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.0 ではなく、2.2.2 が実際にインストールされます。これは、生成される 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.

それは私のカスタム宝石を保持します。この時点で bundle update を実行すると、以下が更新され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

誰でも確認できますか?これは予想される動作ですか?バージョン番号が 1 桁失われた場合に備えて、これはマイナー バージョン番号 0 を避けるための良い議論でしょうか? 例えば

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

1 に答える 1

0

これはあなたの質問に直接答えるものではありませんが。私は過去に同様の問題に直面し、最終的にカスタム gem を他の gem の拡張にしました。つまり、"my-awesome-gem" の機能にパッチを当てるには、"my-awesome-gem-custom" などと呼びます。私を信じてください、あなたがたどっているルートは、依存関係の悪夢に満ちています。:)

ただし、拡張 gem に必要なカスタム Gem 命名の違いに注意する必要があります。これらはわずかに異なるためです。「/x/y/z が必要」対「x_y_z が必要」。このようにすると、Ruby のオープン クラスを使用して、必要に応じて機能をレイヤー化またはオーバーライドできるようになります。

于 2013-01-30T00:33:52.873 に答える