1

我想知道 gem 如何处理它的依赖解析。

例如,当我想安装 gem foodcritic 时,它在 1.5.0 版本中依赖于 nokogiri。

我解压了 foodcritic-1.6.1.gem,但我在任何地方都找不到字符串“1.5.0”、“rubygems.org”或任何可以保存版本信息的东西。

那么“gem”是如何知道 foodcritic 需要 nokogiri-1.5.0 的呢?

我问这个是因为我想手动更改该依赖项。谢谢

编辑:foodcritic-1.6.1 不包含 gemfile 或 gemspec 文件。您可以在http://rubygems.org/gems/foodcritic下找到它

4

1 回答 1

0

它在gemspec中。见https://github.com/acrmp/foodcritic/blob/master/foodcritic.gemspec

...
s.add_dependency('nokogiri', '= 1.5.0')
...

编辑...它在gem文件中...如果您提取它,您将看到metadata.gz。其中包含 gemspec 信息...\

$ ll
total 56
-rw-r--r--@ 1 philip  staff  28160 Nov 13 12:54 foodcritic-1.6.1.gem
philip@Philips-MacBook-Pro:~/Downloads
$ file foodcritic-1.6.1.gem 
foodcritic-1.6.1.gem: POSIX tar archive
philip@Philips-MacBook-Pro:~/Downloads
$ tar xvf foodcritic-1.6.1.gem 
x data.tar.gz
x metadata.gz
philip@Philips-MacBook-Pro:~/Downloads
$ zmore metadata.gz 
------> metadata.gz <------
--- !ruby/object:Gem::Specification
name: foodcritic
version: !ruby/object:Gem::Version
  version: 1.6.1
  prerelease: 
platform: ruby
authors:
- Andrew Crump
autorequire: 
bindir: bin
cert_chain: []
date: 2012-08-30 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
  name: gherkin
  requirement: !ruby/object:Gem::Requirement
    none: false
    requirements:
    - - ~>
      - !ruby/object:Gem::Version
        version: 2.11.1
  type: :runtime
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    none: false
    requirements:
    - - ~>
      - !ruby/object:Gem::Version
        version: 2.11.1
- !ruby/object:Gem::Dependency
  name: gist
  requirement: !ruby/object:Gem::Requirement
    none: false
    requirements:
    - - ~>
      - !ruby/object:Gem::Version
        version: 3.1.0
  type: :runtime
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    none: false
    requirements:
    - - ~>
      - !ruby/object:Gem::Version
        version: 3.1.0
- !ruby/object:Gem::Dependency
  name: nokogiri
  requirement: !ruby/object:Gem::Requirement
    none: false
    requirements:
philip@Philips-MacBook-Pro:~/Downloads
于 2012-11-13T20:53:49.520 回答