Questo contenuto non è disponibile nella lingua selezionata.
Chapter 7. Packaging Ruby gems
Ruby is a dynamic, interpreted, reflective, object-oriented, general-purpose programming language.
Programs written in Ruby are typically packaged by using the RubyGems software, which provides a specific Ruby packaging format.
Packages created by RubyGems are called gems and they can be re-packaged into RPM packages.
This documentation refers to terms related to the RubyGems concept with the gem
prefix, for example, .gemspec
is used for the gem specification, and terms related to RPM are unqualified.
7.1. How RubyGems relate to RPM Copia collegamentoCollegamento copiato negli appunti!
RubyGems represent Ruby’s own packaging format. However, RubyGems contain metadata similar to metadata required by RPM. This metadata streamlines packaging gems as RPMs. RPMs re-packaged from gems fit with the rest of the distribution. End users are also able to satisfy dependencies of a gem by installing the appropriate RPM-packaged gem and other system libraries.
RubyGems use terminology similar to RPM packages, such as spec
files, package names, dependencies, and other items.
To conform with the rest of RHEL RPM distribution, packages created by RubyGems must comply with the following rules:
-
Follow the
rubygem-%{gem_name}
pattern when naming your packages. -
Use the
#!/usr/bin/ruby
string as the interpreter directive.
7.2. RubyGems spec file conventions Copia collegamentoCollegamento copiato negli appunti!
A RubyGems spec
file must meet the following conventions:
-
The file contains a definition of
%{gem_name}
, which is the name from the gem’s specification. - The source of the package must be the full URL to the released gem archive.
- The version of the package must be the gem’s version.
The file contains the following
BuildRequires:
directive:BuildRequires: rubygems-devel
BuildRequires: rubygems-devel
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
rubygems-devel
package contains macros needed for a build.-
The file does not contain any additional
rubygem(foo)
Requires
orProvides
directives because these directives are autogenerated from the gem metadata.
7.2.1. RubyGems spec file example Copia collegamentoCollegamento copiato negli appunti!
The following is the RubyGems-specific part of an example spec
file for building gems. The remaining part of the spec
file follows the generic guidelines.
A RubyGems-specific part of an example spec file
7.2.2. RubyGems spec file directives Copia collegamentoCollegamento copiato negli appunti!
The following are the specifics of particular items in the RubyGems-specific part of the spec
file.
Directive | RubyGems specifics |
---|---|
|
RPM can directly unpack gem archives. The
|
|
This section includes commands for building the software into machine code. The |
|
The installation is performed into the |
7.3. RubyGems macros Copia collegamentoCollegamento copiato negli appunti!
The following are macros useful for packages created by RubyGems. These macros are provided by the rubygems-devel
package.
Macro name | Extended path | Usage |
---|---|---|
|
| Top directory for the gem structure. |
|
| Directory with the actual content of the gem. |
|
| The library directory of the gem. |
|
| The cached gem. |
|
| The gem specification file. |
|
| The RDoc documentation of the gem. |
|
| The directory for gem extension. |
7.4. Using gem2rpm to generate a spec file Copia collegamentoCollegamento copiato negli appunti!
You can use the gem2rpm
utility to create an RPM spec
file.
7.4.1. Creating an RPM spec file for a Ruby gem Copia collegamentoCollegamento copiato negli appunti!
You can generate an RPM spec
file for a RubyGems package by using the gem2rpm
utility.
Prerequisites
You have the
gem2rpm
utility installed on your system:gem install gem2rpm
$ gem install gem2rpm
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Download a gem in its latest version and generate the RPM
spec
file for this gem:gem2rpm --fetch <gem_name> > <gem_name>.spec
$ gem2rpm --fetch <gem_name> > <gem_name>.spec
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Edit the generated
spec
file to add the missing information, for example, a license and a changelog.
7.4.2. Using custom gem2rpm templates to generate a spec file Copia collegamentoCollegamento copiato negli appunti!
gem2rpm
templates are standard Embedded Ruby (ERB) files that RPM spec
files can be generated from. You can edit the template from which the RPM spec
file is generated instead of editing the generated spec
file.
Prerequisites
You have the
gem2rpm
utility installed on your system:gem install gem2rpm
$ gem install gem2rpm
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Display all
gem2rpm
built-in templates:gem2rpm --templates
$ gem2rpm --templates
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Select one of the built-in templates and save it as a custom template:
gem2rpm -t <template> -T > rubygem-<gem_name>.spec.template
$ gem2rpm -t <template> -T > rubygem-<gem_name>.spec.template
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note that for RHEL 10 Beta, the
fedora-27-rawhide
template is recommended.- Edit the template as needed. For more information, see gem2rpm template variables.
Generate the
spec
file by using the edited template:gem2rpm -t rubygem-<gem_name>.spec.template <gem_name>-<latest_version>.gem > <gem_name>-GEM.spec
$ gem2rpm -t rubygem-<gem_name>.spec.template <gem_name>-<latest_version>.gem > <gem_name>-GEM.spec
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
7.4.3. gem2rpm template variables Copia collegamentoCollegamento copiato negli appunti!
The following are the variables included in the gem2rpm
template for RPM spec
file generation.
Variable | Explanation |
---|---|
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |