.gem文件包含什么?它是如何被Rails框架使用的?

时间:2022-10-06 16:54:17

I just created a test gem using bundle and it created a .gem file with unreadable content so I was wondering

我刚刚使用bundle创建了一个测试gem,它创建了一个内容不可读的.gem文件,所以我很想知道

  1. what does that .gem file contains ? is this binary data ? as I used to think that .gem files contains packaged ruby functions

    .gem文件包含什么?这是二进制数据吗?我以前认为.gem文件包含打包的ruby函数

  2. how is this .gem file being used by rails framework ? since it doesn't look like a module

    这个.gem文件是如何被rails框架使用的?因为它看起来不像一个模块

Thanks

谢谢

2 个解决方案

#1


7  

You can see what is happening if you check the file on your file system.

如果检查文件系统上的文件,可以看到发生了什么。

In a Posix environment, you can check the file with the file command:

在Posix环境中,您可以使用file命令检查文件:

$: file bundler-1.3.0.gem          
bundler-1.3.0.gem: POSIX tar archive

As you can see it is a tar archive. So it is a binary file, packaged and managed by the gem tool.

如您所见,它是一个tar存档。所以它是一个二进制文件,由gem工具打包和管理。

It is 'binary' so you will not see it as you may have expected.

这是'二进制'所以你不会像你预期的那样看到它。

You are correct though, and you can continue to think that it contains packaged ruby 'functions'.

你是对的,你可以继续认为它包含打包的ruby'函数'。

Everything that you have told it to contain through your gemspec (however you included it) is there.

你告诉它通过你的gemspec包含的所有东西(不管你包括它)都在那里。

As far as how Rails uses the gemfile, it is used generally by installing the gem to your system, how ever that is done is partially dependent on your environment decisions.

至于Rails如何使用gemfile,通常通过将gem安装到您的系统来使用它,如何完成部分取决于您的环境决策。

#2


5  

A gem file is just a tar archive containing (at least) a gemspec file. There will also usually be ruby source files and possibly native code or supporting assets (for example a gem designed to be used with rails might also package some javascript). It is also common to include a README, CHANGELOG and other documentation.

gem文件只是一个包含(至少)gemspec文件的tar存档。通常还会有ruby源文件以及可能的本机代码或支持资产(例如,设计用于rails的gem也可以打包一些javascript)。包含README,CHANGELOG和其他文档也很常见。

#1


7  

You can see what is happening if you check the file on your file system.

如果检查文件系统上的文件,可以看到发生了什么。

In a Posix environment, you can check the file with the file command:

在Posix环境中,您可以使用file命令检查文件:

$: file bundler-1.3.0.gem          
bundler-1.3.0.gem: POSIX tar archive

As you can see it is a tar archive. So it is a binary file, packaged and managed by the gem tool.

如您所见,它是一个tar存档。所以它是一个二进制文件,由gem工具打包和管理。

It is 'binary' so you will not see it as you may have expected.

这是'二进制'所以你不会像你预期的那样看到它。

You are correct though, and you can continue to think that it contains packaged ruby 'functions'.

你是对的,你可以继续认为它包含打包的ruby'函数'。

Everything that you have told it to contain through your gemspec (however you included it) is there.

你告诉它通过你的gemspec包含的所有东西(不管你包括它)都在那里。

As far as how Rails uses the gemfile, it is used generally by installing the gem to your system, how ever that is done is partially dependent on your environment decisions.

至于Rails如何使用gemfile,通常通过将gem安装到您的系统来使用它,如何完成部分取决于您的环境决策。

#2


5  

A gem file is just a tar archive containing (at least) a gemspec file. There will also usually be ruby source files and possibly native code or supporting assets (for example a gem designed to be used with rails might also package some javascript). It is also common to include a README, CHANGELOG and other documentation.

gem文件只是一个包含(至少)gemspec文件的tar存档。通常还会有ruby源文件以及可能的本机代码或支持资产(例如,设计用于rails的gem也可以打包一些javascript)。包含README,CHANGELOG和其他文档也很常见。