0

我在创建 gem 时仔细记录了 .gemspec 文件,如何访问它的内容?具体来说,我想访问 gem.description 和 gem.summary 条目,因为我在那里放了一些非常有用的信息。

4

2 回答 2

4

我希望有比这更好的答案,阅读 YAML 可能会很烦人,但你可以使用gem specification GEMNAME. 这会吐出很多信息,您可能希望将其通过管道传递给 grep。

于 2012-07-11T03:39:26.213 回答
2

gem specification您可以通过将输出传递到某些东西以提取您想要的内容,从而提供更具可读性的输出。

这可能更清晰,尤其是当描述是多行字符串时:

% gem specification rack description | ruby -ryaml -e 'puts YAML.load(STDIN.read)'
Rack provides a minimal, modular and adaptable interface for developing
web applications in Ruby.  By wrapping HTTP requests and responses in
the simplest way possible, it unifies and distills the API for web 
servers, web frameworks, and software in between (the so-called
middleware) into a single method call.

Also see http://rack.github.com/.

% gem specification hoe description | ruby -ryaml -e 'puts YAML.load(STDIN.read)'
Hoe is a rake/rubygems helper for project Rakefiles. It helps you 
manage, maintain, and release your project and includes a dynamic
plug-in system allowing for easy extensibility. Hoe ships with
plug-ins for all your usual project tasks including rdoc generation,
testing, packaging, deployment, and announcement..

See class rdoc for help. Hint: `ri Hoe` or any of the plugins listed
below.

For extra goodness, see: http://seattlerb.rubyforge.org/hoe/Hoe.pdf
于 2013-01-24T14:56:52.177 回答