class Gem::Specification - Documentation for Ruby 4.0
No recent searches ☰ Gem :: Specification class Gem::Specification 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' s . metadata = { "source_code_uri" => "https://github.com/example/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. Specifications must be deterministic, as in the example above. For instance, you cannot define attributes conditionally: # INVALID: do not do this. unless RUBY_ENGINE == "jruby" s . extensions << "ext/example/extconf.rb" end NONEXISTENT_SPECIFICATION_VERSION The version number of a specification that does not specify one (i.e.
RubyGems 0.7 or earlier). removed_method_calls () Source # File lib/rubygems/specification.rb, line 195 def removed_method_calls @removed_method_calls ||= [] end LATEST_RUBY_WITHOUT_PATCH_VERSIONS bindir [RW] The path in the gem for executable scripts. Usually ‘exe’ Usage: spec . bindir = 'exe' cert_chain [RW] The certificate chain used to sign this gem. See Gem::Security for details. post_install_message [RW] A message that gets displayed after the gem is installed.
Usage: spec . post_install_message = "Thanks for installing!" required_rubygems_version [R] The RubyGems version required by this gem signing_key [RW] The key used to sign this gem. See Gem::Security for details. add_dependency (gem, *requirements) Source # File lib/rubygems/specification.rb, line 564 def add_dependency ( gem , * requirements ) if requirements . uniq . size != requirements . size warn "WARNING: duplicated #{gem} dependency #{requirements}" end add_dependency_with_type ( gem , :runtime , requirements ) end Adds a runtime dependency named gem with requirements to this gem.
Usage: spec . add_dependency 'example' , '~> 1.1' , '>= 1.1.4' Also aliased as: add_runtime_dependency add_development_dependency (gem, *requirements) Source # File lib/rubygems/specification.rb, line 553 def add_development_dependency ( gem , * requirements ) add_dependency_with_type ( gem , :development , requirements ) end 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. author= (o) Source # File lib/rubygems/specification.rb, line 433 def author= ( o ) self . authors = [ o ] end Singular (alternative) writer for authors Usage: spec . author = 'John Jones' executables () Source # File lib/rubygems/specification.rb, line 587 def executables @executables ||= [] end 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' extensions () Source # File lib/rubygems/specification.rb, line 604 def extensions @extensions ||= [] end 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. extra_rdoc_files () Source # File lib/rubygems/specification.rb, line 620 def extra_rdoc_files @extra_rdoc_files ||= [] end 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' ] platform= (platform) Source # File lib/rubygems/specification.rb, line 484 def platform= ( platform ) @original_platform = platform case platform when Gem :: Platform :: CURRENT then @new_platform = Gem :: Platform . local @original_platform = @new_platform . to_s when Gem :: Platform then @new_platform = platform # legacy constants when nil , Gem :: Platform :: RUBY then @new_platform = Gem :: Platform :: RUBY when "mswin32" then # was Gem::Platform::WIN32 @new_platform = Gem :: Platform . new "x86-mswin32" when "i586-linux" then # was Gem::Platform::LINUX_586 @new_platform = Gem :: Platform . new "x86-linux" when "powerpc-darwin" then # was Gem::Platform::DARWIN @new_platform = Gem :: Platform . new "ppc-darwin" else @new_platform = Gem :: Platform . new platform end @platform = @new_platform . to_s end 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 rdoc_options () Source # File lib/rubygems/specification.rb, line 650 def rdoc_options @rdoc_options ||= [] end Specifies the rdoc options to be used when generating API documentation.
Usage: spec . rdoc_options << '--title' << 'Rake -- Ruby Make' << '--main' << 'README' << '--line-numbers' require_paths= (val) Source # File lib/rubygems/specification.rb, line 528 def require_paths= ( val ) @require_paths = Array ( val ) end 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 = [ '.' ] required_ruby_version= (req) Source # File lib/rubygems/specification.rb, line 680 def required_ruby_version= ( req ) @required_ruby_version = Gem :: Requirement . create req @required_ruby_version . requirements . map! do | op , v | if v >= LATEST_RUBY_WITHOUT_PATCH_VERSIONS && v . release . segments . size == 4 [ op == "~>" ?
"=" : op , Gem :: Version . new ( v . segments . tap { | s | s . delete_at ( 3 ) }. join ( "." ))] else [ op , v ] end end end 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"> Prereleases can also be specified. Usage: # This gem will work with 1.8.6 or greater... spec . required_ruby_version = '>= 1.8.6' # Only with final releases of major version 2 where minor version is at least 3 spec . required_ruby_version = '~> 2.3' # Only prereleases or final releases after 2.6.0.preview2 spec . require
The rest of this page is on the live site.