Once I have installed a Ruby gem I know that I can see the files inside the gem by using gem contents <my_gem>. But how can I see the contents of a gem without installing it?
gem unpack
You can use the gem unpack command to extract the contents of a .gem file into a directory. Assuming you have some_file.gem:
gem unpack some_file.gem
tar
If you want to list the gem's contents without unpacking it, you can use tar (a .gem file is just a .tar file with a specific format).
tar --to-stdout -xf some_file.gem data.tar.gz | tar -zt
Here's a longer explanation of how this works:
# Download a .gem file
$ gem fetch json_pure -v '2.0.3'
Fetching: json_pure-2.0.3.gem (100%)
Downloaded json_pure-2.0.3
# List the contents of the gem
# You can see that it contains separate files for metadata, the gem files, and a checksum
$ tar -tf json_pure-2.0.3.gem
metadata.gz
data.tar.gz
checksums.yaml.gz
# Extract just the data.tar.gz file, then unzip and list the contents of *that* file.
# --to-stdout so we can pipe it to another command
# -x extract
# -f file
#
# Then:
# -z use gunzip to decompress the .tar.gz file
# -t list the contents of the archive
tar --to-stdout -xf json_pure-2.0.3.gem data.tar.gz | tar -zt
./tests/test_helper.rb
.gitignore
.travis.yml
CHANGES.md
Gemfile
...
In most cases gem unpack is probably what you want. The main benefit to the tar command above is that it doesn't create any new directories or actually unpack the files. It might also be useful if you don't have rubygems installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With