Class Gem::Specification
In: lib/rubygems/specification.rb
Parent: Object

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

  spec = Gem::Specification.new do |s|
    s.name = 'rfoo'
    s.version = '1.0'
    s.summary = 'Example gem specification'
    ...
  end

For a great way to package gems, use Hoe.

Constants

NONEXISTENT_SPECIFICATION_VERSION = -1   The the version number of a specification that does not specify one (i.e. RubyGems 0.7 or earlier).
CURRENT_SPECIFICATION_VERSION = 3   The specification version applied to any new Specification instances created. This should be bumped whenever something in the spec format changes.
SPECIFICATION_VERSION_HISTORY = { -1 => ['(RubyGems versions up to and including 0.7 did not have versioned specifications)'], 1 => [ 'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"', '"test_file=x" is a shortcut for "test_files=[x]"' ], 2 => [ 'Added "required_rubygems_version"', 'Now forward-compatible with future versions', ], 3 => [ 'Added Fixnum validation to the specification_version' ] }   An informal list of changes to the specification. The highest-valued key should be equal to the CURRENT_SPECIFICATION_VERSION.

External Aliases

loaded -> loaded?
  True if this gem was loaded from disk
== -> eql?

Attributes

loaded  [RW]  true when this gemspec has been loaded from a specifications directory. This attribute is not persisted.
loaded_from  [RW]  Path this gemspec was loaded from. This attribute is not persisted.

Public Class methods

Load custom marshal format, re-initializing defaults as needed

Same as :attribute, but ensures that values assigned to the attribute are array values by applying :to_a to the value.

Specification attributes that are arrays (appendable and so-forth)

Specifies the name and default for a specification attribute, and creates a reader and writer method like Module#attr_accessor.

The reader method returns the default if the value hasn’t been set.

Defines a singular version of an existing plural attribute (i.e. one whose value is expected to be an array). This means just creating a helper method that takes a single value and appends it to the array. These are created for convenience, so that in a spec, one can write

  s.require_path = 'mylib'

instead of:

  s.require_paths = ['mylib']

That above convenience is available courtesy of:

  attribute_alias_singular :require_path, :require_paths

Default values for specification attributes

Names of all specification attributes

Shortcut for creating several attributes at once (each with a default value of nil).

The default value for specification attribute name

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.

Loads ruby format gemspec from filename

Specification constructor. Assigns the default values to the attributes and yields itself for further initialization.

Make sure the YAML specification is properly formatted with dashes

Some attributes require special behaviour when they are accessed. This allows for that.

Sometimes we don’t want the world to use a setter method for a particular attribute.

read_only makes it private so we can still use it internally.

Same as attribute above, but also records this attribute as mandatory.

Is name a required attribute?

Required specification attributes

Public Instance methods

Dump only crucial instance variables.

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

add_dependency(gem, *requirements)

Adds a development dependency named gem with requirements to this Gem. For example:

  spec.add_development_dependency 'jabber4r', '> 0.1', '<= 0.5'

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. For example:

  spec.add_runtime_dependency 'jabber4r', '> 0.1', '<= 0.5'

Each attribute has a default value (possibly nil). Here, we initialize all attributes to their default value. This is done through the accessor methods, so special behaviours will be honored. Furthermore, we take a copy of the default so each specification instance has its own empty arrays, etc.

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]]

List of dependencies that are used for development

The default (generated) file name of the gem.

The full path to the gem (install path + full name).

Returns the full name (name-version) of this Gem. Platform information is included (name-version-platform) if it is specified and not the default Ruby platform.

True if this gem has files in test_files

Duplicates array_attributes from other_spec so state isn’t shared.

The directory that this gem was installed into.

Files in the Gem under one of the require_paths

Sets the rubygems_version to the current RubyGems version

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.

List of depedencies that will automatically be activated at runtime.

Checks if this specification meets the requirement of dependency.

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

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.

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..

Required gemspec attributes

Public Instance methods

:attr_accessor: date

The date this gem was created

:attr_accessor: name

This gem’s name

:attr_accessor: require_paths

Paths in the gem to add to $LOAD_PATH when this gem is activated

:attr_accessor: rubygems_version

The version of RubyGems used to create this gem

:attr_accessor: specification_version

The Gem::Specification version of this gemspec

:attr_accessor: summary

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

:attr_accessor: version

This gem’s version

Optional gemspec attributes

Public Instance methods

:attr_accessor: authors

The list of authors who wrote this gem

:attr_accessor: autorequire

Autorequire was used by old RubyGems to automatically require a file. It no longer is supported.

:attr_accessor: bindir

The path in the gem for executable scripts

:attr_accessor: cert_chain

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

:attr_accessor: default_executable

The default executable for this gem.

:attr_reader: dependencies

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

:attr_accessor: description

A long description of this gem

:attr_accessor: email

A contact email for this gem

:attr_accessor: executables

Executables included in the gem

:attr_accessor: extensions

Extensions to build when installing the gem. See Gem::Installer#build_extensions for valid values.

:attr_accessor: extra_rdoc_files

Extra files to add to RDoc

:attr_accessor: files

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.

:attr_accessor: has_rdoc

Deprecated and ignored, defaults to true.

Formerly used to indicate this gem was RDoc-capable.

has_rdoc?()

Alias for has_rdoc

:attr_accessor: homepage

The URL of this gem’s home page

:attr_accessor: licenses

The license(s) for the library. Each license must be a short name, no more than 64 characters.

:attr_accessor: platform

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

:attr_accessor: post_install_message

A message that gets displayed after the gem is installed

:attr_accessor: rdoc_options

An ARGV-style array of options to RDoc

:attr_accessor: required_ruby_version

The ruby of version required by this gem

:attr_accessor: required_rubygems_version

The RubyGems version required by this gem

:attr_accessor: requirements

An array or things required by this gem. Not used by anything presently.

:attr_accessor: rubyforge_project

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

:attr_accessor: signing_key

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

:attr_accessor: test_files

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

Aliased gemspec attributes

Public Instance methods

Singular accessor for authors

Singular accessor for executables

has_rdoc is now ignored

Singular accessor for licenses

Singular accessor for require_paths

Singular accessor for test_files