The Specification class contains the information for a Gem. Typically defined in a .gemspec file or a Rakefile, and looks like this:

Gem::Specification.new do |s|
  s.name        = 'example'
  s.version     = '0.1.0'
  s.licenses    = ['MIT']
  s.summary     = "This is an example!"
  s.description = "Much longer explanation of the example!"
  s.authors     = ["Ruby Coder"]
  s.email       = 'rubycoder@example.com'
  s.files       = ["lib/example.rb"]
  s.homepage    = 'https://rubygems.org/gems/example'
end

Starting in RubyGems 2.0, a Specification can hold arbitrary metadata. See metadata for restrictions on the format and size of metadata items you may add to a specification.

Constants

The version number of a specification that does not specify one (i.e. RubyGems 0.7 or earlier).

The specification version applied to any new Specification instances created. This should be bumped whenever something in the spec format changes.

Specification Version History:

spec   ruby
 ver    ver yyyy-mm-dd description
  -1 <0.8.0            pre-spec-version-history
   1  0.8.0 2004-08-01 Deprecated "test_suite_file" for "test_files"
                       "test_file=x" is a shortcut for "test_files=[x]"
   2  0.9.5 2007-10-01 Added "required_rubygems_version"
                       Now forward-compatible with future versions
   3  1.3.2 2009-01-03 Added Fixnum validation to specification_version
   4  1.9.0 2011-06-07 Added metadata

An informal list of changes to the specification. The highest-valued key should be equal to the CURRENT_SPECIFICATION_VERSION.

No documentation available
No documentation available
No documentation available
No documentation available

Sentinel object to represent “not found” stubs

No documentation available
No documentation available
No documentation available
Attributes
Read & Write

This gem’s name.

Usage:

spec.name = 'rake'
Read

This gem’s version.

The version string can contain numbers and periods, such as 1.0.0. A gem is a ‘prerelease’ gem if the version has a letter in it, such as 1.0.0.pre.

Usage:

spec.version = '0.4.1'
Read & Write

The version of RubyGems used to create this gem.

Do not set this, it is set automatically when the gem is packaged.

Read

A short summary of this gem’s description. Displayed in ‘gem list -d`.

The description should be more detailed than the summary.

Usage:

spec.summary = "This is a small summary of my gem"
Read & Write

The path in the gem for executable scripts. Usually ‘bin’

Usage:

spec.bindir = 'bin'
Read & Write

The certificate chain used to sign this gem. See Gem::Security for details.

A long description of this gem

The description should be more detailed than the summary but not excessively long. A few paragraphs is a recommended length with no examples or formatting.

Usage:

spec.description = <<-EOF
  Rake is a Make-like program implemented in Ruby. Tasks and
  dependencies are specified in standard Ruby syntax.
EOF
Read & Write

A contact email address (or addresses) for this gem

Usage:

spec.email = 'john.jones@example.com'
spec.email = ['jack@example.com', 'jill@example.com']
Read & Write

The URL of this gem’s home page

Usage:

spec.homepage = 'https://github.com/ruby/rake'
Read & Write

A message that gets displayed after the gem is installed.

Usage:

spec.post_install_message = "Thanks for installing!"

The version of Ruby required by this gem

The RubyGems version required by this gem

Read & Write

The key used to sign this gem. See Gem::Security for details.

Read & Write

:attr_accessor: metadata

The metadata holds extra data for this gem that may be useful to other consumers and is settable by gem authors without requiring an update to the rubygems software.

Metadata items have the following restrictions:

  • The metadata must be a Hash object

  • All keys and values must be Strings

  • Keys can be a maximum of 128 bytes and values can be a maximum of 1024 bytes

  • All strings must be UTF-8, no binary data is allowed

To add metadata for the location of a issue tracker:

s.metadata = { "issue_tracker" => "https://example/issues" }
Read & Write

True when this gemspec has been activated. This attribute is not persisted.

Read & Write

True when this gemspec has been activated. This attribute is not persisted.

Sets the default executable for this gem.

Deprecated: You must now specify the executable name to Gem.bin_path.

Read & Write

The rubyforge project this gem lives under. i.e. RubyGems’ rubyforge_project is “rubygems”.

This option is deprecated.

Read & Write

The Gem::Specification version of this gemspec.

Do not set this, it is set automatically when the gem is packaged.

Class Methods

Load custom marshal format, re-initializing defaults as needed

Adds spec to the known specifications, keeping the collection properly sorted.

Adds multiple specs to the known specifications.

Returns all specifications. This method is discouraged from use. You probably want to use one of the Enumerable methods instead.

Sets the known specs to specs. Not guaranteed to work for you in the future. Use at your own risk. Caveat emptor. Doomy doom doom. Etc etc.

Return full names of all specs in sorted order.

Return the list of all array-oriented instance variables.

Return the list of all instance variables.

No documentation available

Return the directories that Specification uses to find specs.

Set the directories that Specification uses to find specs. Setting this resets the list of known specs.

Enumerate every known spec. See ::dirs= and ::add_spec to set the list of specs.

No documentation available

Returns every spec that matches name and optional requirements.

Find the best specification matching a name and requirements. Raises if the dependency doesn’t resolve to a valid specification.

Return the best specification that contains the file matching path.

Return currently unresolved specs that contain the file matching path.

Search through all unresolved deps and sub-dependencies and return specs that contain the file matching path.

Return the best specification that contains the file matching path amongst the specs that are not activated.

Special loader for YAML files. When a Specification object is loaded from a YAML file, it bypasses the normal Ruby object initialization routine (initialize). This method makes up for that and deals with gems of different ages.

input can be anything that YAML.load() accepts: String or IO.

No documentation available
No documentation available

Return the latest specs, optionally including prerelease specs if prerelease is true.

Loads Ruby format gemspec from file.

Loads the default specifications. It should be called only once.

Specification constructor. Assigns the default values to the attributes and yields itself for further initialization. Optionally takes name and version.

Specification attributes that must be non-nil

Make sure the YAML specification is properly formatted with dashes

Return a list of all outdated local gem names. This method is HEAVY as it must go fetch specifications from the server.

Use outdated_and_latest_version if you wish to retrieve the latest remote version as well.

Enumerates the outdated local gems yielding the local specification and the latest remote version.

This method may take some time to return as it must check each local gem against the server’s index.

Removes spec from the known specs.

Is name a required attribute?

Required specification attributes

Reset the list of known specs, running pre and post reset hooks registered in Gem.

No documentation available

Returns a Gem::StubSpecification for every installed gem

Returns a Gem::StubSpecification for installed gem named name

DOC: This method needs documented or nodoc’d

Instance Methods

Dump only crucial instance variables.

Abbreviate the spec for downloading. Abbreviated specs are only used for searching, downloading and related activities and do not need deployment specific information (e.g. list of files). So we abbreviate the spec, making it much smaller for quicker downloads.

Activate this spec, registering it as a loaded spec and adding it’s lib paths to $LOAD_PATH. Returns true if the spec was activated, false if it was previously activated. Freaks out if there are conflicts upon activation.

Activate all unambiguously resolved runtime dependencies of this spec. Add any ambiguous dependencies to the unresolved list to be resolved later, as needed.

Returns an array with bindir attached to each executable in the executables list

Adds a dependency on gem dependency with type type that requires requirements. Valid types are currently :runtime and :development.

Adds a development dependency named gem with requirements to this gem.

Usage:

spec.add_development_dependency 'example', '~> 1.1', '>= 1.1.4'

Development dependencies aren’t installed by default and aren’t activated when a gem is required.

Adds a runtime dependency named gem with requirements to this gem.

Usage:

spec.add_runtime_dependency 'example', '~> 1.1', '>= 1.1.4'

Adds this spec’s require paths to LOAD_PATH, in the proper location.

Singular reader for authors. Returns the first author in the list

Singular writer for authors

Usage:

spec.author = 'John Jones'

The list of author names who wrote this gem.

spec.authors = ['Chad Fowler', 'Jim Weirich', 'Rich Kilmer']

Sets the list of authors, ensuring it is an array.

Usage:

spec.authors = ['John Jones', 'Mary Smith']
No documentation available

Returns the full path to installed gem’s bin directory.

NOTE: do not confuse this with bindir, which is just ‘bin’, not a full path.

Returns the full path to an executable named name in this gem.

Returns the build_args used to install the gem

Returns the full path to the build info directory

Returns the full path to the file containing the build information generated when the gem was installed

Used to detect if the gem is bundled in older version of Ruby, but not detectable as default gem (see BasicSpecification#default_gem?).

Returns the full path to the cache directory containing this spec’s cached gem.

Returns the full path to the cached gem for this spec.

Return any possible conflicts against the currently loaded specs.

The date this gem was created. Lazily defaults to the current UTC date.

There is no need to set this in your gem specification.

The date this gem was created

DO NOT set this, it is set automatically when the gem is packaged.

The default value for specification attribute name

A list of Gem::Dependency objects this gem depends on.

Use add_dependency or add_development_dependency to add dependencies to a gem.

Return a list of all gems that have a dependency on this gemspec. The list is structured with entries that conform to:

[depending_gem, dependency, [list_of_gems_that_satisfy_dependency]]

Returns all specs that matches this spec’s runtime dependencies.

A detailed description of this gem. See also summary

List of dependencies that are used for development

Returns the full path to this spec’s documentation directory. If type is given it will be appended to the end. For example:

spec.doc_dir      # => "/path/to/gem_repo/doc/a-1"

spec.doc_dir 'ri' # => "/path/to/gem_repo/doc/a-1/ri"

Singular accessor for executables

Singular accessor for executables

Executables included in the gem.

For example, the rake gem has rake as an executable. You don’t specify the full path (as in bin/rake); all application-style files are expected to be found in bindir. These files must be executable Ruby files. Files that use bash or other interpreters will not work.

Executables included may only be ruby scripts, not scripts for other languages or compiled binaries.

Usage:

spec.executables << 'rake'

Sets executables to value, ensuring it is an array. Don’t use this, push onto the array instead.

Extensions to build when installing the gem, specifically the paths to extconf.rb-style files used to compile extensions.

These files will be run when the gem is installed, causing the C (or whatever) code to be compiled on the user’s machine.

Usage:

spec.extensions << 'ext/rmagic/extconf.rb'

See Gem::Ext::Builder for information about writing extensions for gems.

Sets extensions to extensions, ensuring it is an array. Don’t use this, push onto the array instead.

Extra files to add to RDoc such as README or doc/examples.txt

When the user elects to generate the RDoc documentation for a gem (typically at install time), all the library files are sent to RDoc for processing. This option allows you to have some non-code files included for a more complete set of documentation.

Usage:

spec.extra_rdoc_files = ['README', 'doc/user-guide.txt']

Sets extra_rdoc_files to files, ensuring it is an array. Don’t use this, push onto the array instead.

The default (generated) file name of the gem. See also spec_name.

spec.file_name # => "example-1.0.gem"

Files included in this gem. You cannot append to this accessor, you must assign to it.

Only add files you can require to this list, not directories, etc.

Directories are automatically stripped from this list when building a gem, other non-files cause an error.

Usage:

require 'rake'
spec.files = FileList['lib/**/*.rb',
                      'bin/*',
                      '[A-Z]*',
                      'test/**/*'].to_a

# or without Rake...
spec.files = Dir['lib/**/*.rb'] + Dir['bin/*']
spec.files += Dir['[A-Z]*'] + Dir['test/**/*']
spec.files.reject! { |fn| fn.include? "CVS" }

Sets files to files, ensuring it is an array.

Finds all gems that satisfy dep

Creates a duplicate spec without large blobs that aren’t used at runtime.

No documentation available
No documentation available

Return true if there are possible conflicts against the currently loaded specs.

Duplicates array_attributes from other_spec so state isn’t shared.

Expire memoized instance variables that can incorrectly generate, replace or miss files due changes in certain attributes used to compute them.

Files in the Gem under one of the require_paths

Singular accessor for licenses

The license for this gem.

The license must be no more than 64 characters.

This should just be the name of your license. The full text of the license should be inside of the gem (at the top level) when you build it.

The simplest way, is to specify the standard SPDX ID spdx.org/licenses/ for the license. Ideally you should pick one that is OSI (Open Source Initiative) opensource.org/licenses/alphabetical approved.

The most commonly used OSI approved licenses are MIT and Apache-2.0. GitHub also provides a license picker at choosealicense.com/.

You should specify a license for your gem so that people know how they are permitted to use it, and any restrictions you’re placing on it. Not specifying a license means all rights are reserved; others have no rights to use the code for any purpose.

You can set multiple licenses with licenses=

Usage:

spec.license = 'MIT'

Plural accessor for setting licenses

See license= for details

The license(s) for the library.

Each license must be a short name, no more than 64 characters.

This should just be the name of your license. The full text of the license should be inside of the gem when you build it.

See license= for more discussion

Usage:

spec.licenses = ['MIT', 'GPL-2.0']

Sets the rubygems_version to the current RubyGems version.

Is this specification missing its extensions? When this returns true you probably want to build_extensions

Return a NameTuple that represents this Specification

Normalize the list of files so that:

  • All file lists have redundancies removed.

  • Files referenced in the extra_rdoc_files are included in the package file list.

The platform this gem runs on. See Gem::Platform for details.

The platform this gem runs on.

This is usually Gem::Platform::RUBY or Gem::Platform::CURRENT.

Most gems contain pure Ruby code; they should simply leave the default value in place. Some gems contain C (or other) code to be compiled into a Ruby “extension”. The gem should leave the default value in place unless the code will only compile on a certain type of system. Some gems consist of pre-compiled code (“binary gems”). It’s especially important that they set the platform attribute appropriately. A shortcut is to set the platform to Gem::Platform::CURRENT, which will cause the gem builder to set the platform to the appropriate value for the system on which the build is being performed.

If this attribute is set to a non-default value, it will be included in the filename of the gem when it is built such as: nokogiri-1.6.0-x86-mingw32.gem

Usage:

spec.platform = Gem::Platform.local

Specifies the rdoc options to be used when generating API documentation.

Usage:

spec.rdoc_options << '--title' << 'Rake -- Ruby Make' <<
  '--main' << 'README' <<
  '--line-numbers'

Sets rdoc_options to value, ensuring it is an array. Don’t use this, push onto the array instead.

Singular accessor for require_paths

Singular accessor for require_paths

Paths in the gem to add to $LOAD_PATH when this gem is activated. If you have an extension you do not need to add "ext" to the require path, the extension build process will copy the extension files into “lib” for you.

The default value is "lib"

Usage:

# If all library files are in the root directory...
spec.require_paths = ['.']

The version of Ruby required by this gem. The ruby version can be specified to the patch-level:

$ ruby -v -e 'p Gem.ruby_version'
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
#<Gem::Version "2.0.0.247">

Because patch-level is taken into account, be very careful specifying using ‘<=`: `<= 2.2.2` will not match any patch-level of 2.2.2 after the `p0` release. It is much safer to specify `< 2.2.3` instead

Usage:

# This gem will work with 1.8.6 or greater...
spec.required_ruby_version = '>= 1.8.6'

# Only with ruby 2.0.x
spec.required_ruby_version = '~> 2.0'

# Only with ruby between 2.2.0 and 2.2.2
spec.required_ruby_version = ['>= 2.2.0', '< 2.2.3']

The RubyGems version required by this gem

Lists the external (to RubyGems) requirements that must be met for this gem to work. It’s simply information for the user.

Usage:

spec.requirements << 'libmagick, v6.0'
spec.requirements << 'A good graphics card'

Set requirements to req, ensuring it is an array. Don’t use this, push onto the array instead.

Reset nil attributes to their default values to make the spec valid

Returns the full path to this spec’s ri directory.

Return a string containing a Ruby code representation of the given object.

List of dependencies that will automatically be activated at runtime.

True if this gem has the same attributes as other.

Sanitize the descriptive fields in the spec. Sometimes non-ASCII characters will garble the site index. Non-ASCII characters will be replaced by their XML entity equivalent.

Sanitize a single string.

Checks if this specification meets the requirement of dependency.

Returns an object you can use to sort specifications in sort_by.

Returns the full path to the directory containing this spec’s gemspec file. eg: /usr/local/lib/ruby/gems/1.8/specifications

Returns the full path to this spec’s gemspec file. eg: /usr/local/lib/ruby/gems/1.8/specifications/mygem-1.0.gemspec

The default name of the gemspec. See also file_name

spec.spec_name # => "example-1.0.gemspec"
No documentation available

A short summary of this gem’s description.

Returns a Ruby code representation of this specification, such that it can be eval’ed and reconstruct the same specification later. Attributes that still have their default values are omitted.

Returns a Ruby lighter-weight code representation of this specification, used for indexing only.

See to_ruby.

Returns self

Recursively walk dependencies of this spec, executing the block for each hop.

Checks that the specification contains all required fields, and does a very basic sanity check.

Raises InvalidSpecificationException if the spec does not pass the checks..

Checks to see if the files to be packaged are world-readable.

Set the version to version, potentially also setting required_rubygems_version if version indicates it is a prerelease.