52

不熟悉生态系统的 Ruby 涉猎者/新手在这里,如果这是那些超级无聊的问题之一,我们深表歉意。

有没有办法查看gem 安装的所有文件和/或源代码?也就是说,我只是跑了

$ gem install sass

sass gem 现在是我本地系统的一部分

$ gem list --local
...
sass (3.1.16, 3.1.2)
...

我想知道gem install命令放在我的系统上的内容。有没有可以运行的命令来查看gem 安装的 所有文件?

经过一番谷歌搜索,man gemand gem help commands,我发现了这个contents命令。

$ gem 内容 sass

但是,当我使用上述 sass gem 运行此命令时,我得到以下结果

.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/engine_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/functions_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/extend_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/logger_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/css2sass_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/conversion_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/script_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/util/subset_map_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/util/multibyte_string_scanner_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/callbacks_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/importer_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/scss/css_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/scss/scss_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/scss/rx_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/util_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/script_conversion_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/less_conversion_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/cache_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/plugin_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/bin/sass
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/bin/sass-convert
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/bin/scss

但是,此列表似乎不完整,因为我知道其中有文件

.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.2/lib/

为什么不contents显示来自的文件lib

安装程序是否可以gem在 gems 文件夹之外安装文件?

是否有一个命令可以显示gem 安装的所有内容?

4

6 回答 6

62

gem has an unpack command: http://guides.rubygems.org/command-reference/#gem-unpack

gem unpack rake
ls rake-0.4.3/
于 2012-05-04T17:34:14.717 回答
39

There are two really good ways to do this. There is another gem which allows you to open the gem and edit. This gem is call gem-open

gem install gem-open 

then

gem open sass

Another way is to generate your own rdocs.

gem rdoc sass

You can then look at your rdocs by

gem server

Also if you are using rvm, you can type rvm info and it will show GEM_HOME location. This will be where all your gems source code is.

cd $GEM_HOME
cd gems/sass-3.1.2/

Update:

This is the way I mostly do this now, when using bundler.

cd $(bundle show sass) 

This will be the version of sass in your Gemfile.

于 2012-05-04T17:34:37.180 回答
17

我通常通过从控​​制台运行此命令来打开 gem

EDITOR=<your editor> bundle open <name of gem>
于 2015-04-21T11:26:28.653 回答
7

您提到的 lib/ 目录适用于 gem 的 3.1.2 版本;gem contentswithout--version只会列出一个版本(它似乎选择了最新版本,但我无法验证这总是正确的)。你得到什么输出gem contents --version 3.1.2 sass

于 2012-05-05T17:08:16.297 回答
3

您也可以使用将 .gem 文件重命名为 .tar 并提取为 posix 存档。源代码在lib文件夹中。有关更多详细信息,请参阅https://blog.srcclr.com/extracting-ruby-source-code-from-gem-packages/

于 2015-04-11T03:03:58.313 回答
2

此外gem contents,您可能会发现另一个有用的命令是gem environment. 如果您的 gem 安装有多个路径,它们都将列在“GEM PATHS”标签下。

于 2016-04-06T20:13:45.923 回答