ruby gem依赖解析如何工作?

时间:2012-11-13 20:19:52

标签: ruby gem dependencies version

我想知道gem如何处理其依赖性解析。

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

我解压缩了foodcritic-1.6.1.gem,但我找不到字符串“1.5.0”,“rubygems.org”或其他可以保存版本信息的字符串。

那么'宝石'怎么知道食物批评需要nokogiri-1.5.0?

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

编辑:foodcritic-1.6.1没有gemfile或gemspec文件。您可以在http://rubygems.org/gems/foodcritic

下找到它

1 个答案:

答案 0 :(得分:0)

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

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

编辑...它在宝石文件中......如果你提取它,你会看到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