|
|
RubyGems GemSpec ReferenceGemspec ReferenceSpecification ReferenceThis page is generated by hieraki rake task in the RubyGems CVS. Any changes to this page will be lost. Contact a member of the RubyGems team if you have suggestions. Last generated: 2005-06-01 00:11:33 EDT (Wednesday) IntroductionIn order to create a gem, you need to define a gem specification, commonly called a “gemspec”. A gemspec consists of several attributes. Some of these are required; most of them are optional. The main body of this document is an alphabetical list of gemspec attributes, each with a description, example usage, notes, and more. See also: Important Attributesname .. version .. platform .. summary .. require_paths .. files .. dependencies Alphabetical
Themed
Attribute SurveyauthorsType: String; Optional DescriptionThe author of the package contained in the gem. Usagespec.author = "John Jones" Goto Table of Contents autorequireType: String; Optional; default = nil DescriptionThe file that will be loaded when require_gem is called. Usagespec.files = ['lib/rake.rb", "lib/rake/**/*.rb", ...] spec.autorequire = 'rake' NotesIn the above example, when the user’s code calls require_gem ‘rake’, an implicit require ‘rake’ is called afterwards. It is a shortcut so the user doesn’t have to do what seems to be a redundant require. Specifying autorequire is optional. If there is no single default file that should be loaded, then it doesn’t make sense to specify it. Goto Table of Contents bindirType: String; Optional; default = “bin” DescriptionThe directory containing the application files, if any. Usagespec.bindir = 'bin' NotesAn “application file” is a file that is intended to be run from the command line. If your package contains such files, they will typically be placed in a bin directory, hence the name bindir. Goto Table of Contents dateType: Time; Required; default = “Time.now” DescriptionThe date/time that the gem was created. Usage
spec.date = File.utime('VERSION')
NotesIt’s generally sufficient to leave it to the default. Goto Table of Contents default_executableType: String; Optional; default = (see below) DescriptionOf all the application files in the package, the default executable is the one that can be run directly through the gem. Usagespec.executables = ['bin/foo', 'bin/bar'] spec.default_executable = 'bin/bar' NotesIf you only specify one application file in executables, that file becomes the default executable. Therefore, you only need to specify this value if you have more than one application file. The notion of running applications directly through a gem is not well supported at the moment. The idea is that you can download a gem, say monopoly.gem (the board game), and run gem monopoly.gem, which would run the monopoly application. This is not an in-demand feature. XXX: Is the full path necessary? Goto Table of Contents dependenciesType: Array; Optional; default = [] DescriptionLists the gems that must be installed for this gem to work. Usage
spec.add_dependency('log4r', '>= 1.0.5')
NotesWhen installing a gem with gem install …, its dependencies will be checked. If they are not installed, gem will offer to install them. See also requirements. Goto Table of Contents descriptionType: String; Optional DescriptionDetailed description of the gem. See also summary. Usage
spec.description = <<-EOF
Rake is a Make-like program implemented in Ruby. Tasks and
dependencies are specified in standard Ruby syntax.
EOF
NotesWhen the gem is built, the description is re-formatted into a single line with sensible whitespace. This means you can use here-docs with formatting, as demonstrated above, without worrying about the formatting. The description should be more detailed than the summary. You might consider copying all or part of your project’s README into this field. Goto Table of Contents Type: String; Optional DescriptionThe author’s email address. Usagespec.email = 'john.jones@example.com' Goto Table of Contents executablesType: Array; Optional DescriptionA list of files in the package that are applications. Usage# XXX: is this correct? spec.executables << 'rake' NotesFor 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. Goto Table of Contents extensionsType: Array; Optional DescriptionThe paths to extconf.rb-style files used to compile extensions. Usagespec.extensions << 'ext/rmagic/extconf.rb' NotesThese files will be run when the gem is installed, causing the C (or whatever) code to be compiled on the user’s machine. XXX: Any other comments? Goto Table of Contents extra_rdoc_filesType: Array; Optional DescriptionA list of extra files that will be used by RDoc to generate the documentation. Usagespec.extra_rdoc_files = ['README', 'doc/user-guide.txt'] NotesWhen 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. Goto Table of Contents filesType: Array; Optional DescriptionThe list of files to be contained in the gem. 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" }
NotesYou don’t need to use Rake, obviously, but it does make it much easier to specify files, as it automatically excludes CVS files, backups, etc. Goto Table of Contents has_rdocType: boolean; Optional; default = false DescriptionIndicates whether the code in the gem has been commented with RDoc in mind. Usagespec.has_rdoc = true NotesThis attribute has an advisory role only. Any gem can be submitted for RDoc processing. Goto Table of Contents homepageType: String; Optional DescriptionURL of the project or author. Usagespec.hompage = 'http://rake.rubyforge.org' Goto Table of Contents nameType: String; Required DescriptionThe name of the gem. Usagespec.name = 'rake' NotesThe name does not include the version number; see version. Goto Table of Contents platformType: String; Required; default = “Gem::Platform::Ruby” DescriptionThe target platform for the gem. Usagespec.platform = Gem::Platform::Win32 NotesMost 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 should leave the default value in place unless their 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, e.g. fxruby-1.2.0-win32.gem. Goto Table of Contents rdoc_optionsType: Array; Optional; default = [] DescriptionSpecifies the rdoc options to be used when generating API documentation. Usage
spec.rdoc_options << '--title' << 'Rake -- Ruby Make' <<
'--main' << 'README' <<
'--line-numbers'
Goto Table of Contents require_pathsType: Array; Required; default = [“lib”] DescriptionList of ’’require’’ paths from the root of the gem. Usage# If all library files are in the root directory... spec.require_path = '.' # If you have 'lib' and 'ext' directories... spec.require_paths << 'ext' NotesThe default is sufficient in most cases, as Ruby packages tend to be structured so that library code is found under the lib directory. The example above shows that you can use spec.require_path = ’...’ instead of spec.require_paths = [...]. This is a shortcut, acknowledging that nearly all gems will have only one require path element. Be careful about interpreting this attribute, however. It is used to modify the LOAD_PATH, and thus to resolve require calls. So if code calls require ‘rake/packagetask’, for example, and the require_paths is set to lib, then there had better be a file lib/rake/packagetask.rb. Goto Table of Contents required_ruby_versionType: Gem::Version::Requirement; Optional; default = ”> 0.0.0” DescriptionThe version of Ruby required to use the gem. Usage# If it will work with 1.6.8 or greater... spec.required_ruby_version = '>= 1.6.8' # ...but not with 1.7/1.8... spec.required_ruby_version = '~> 1.6.8' # The typical case these days... spec.required_ruby_version = '>= 1.8.1' NotesSee the RubyGems wiki for documentation on specifying versions. Goto Table of Contents requirementsType: Array; Optional; default = [] DescriptionLists the external (to Usagespec.requirements << 'libmagick, v6.0 or greater' spec.requirements << 'A powerful graphics card' NotesFor requirements that can be met by other gems, see dependencies. Goto Table of Contents rubyforge_projectType: String; Optional DescriptionThe RubyForge project corresponding to the gem. Usagespec.rubyforge_project = 'rake' NotesObviously, if your gem doesn’t have a Rubyforge project, leave this setting alone. Goto Table of Contents rubygems_versionType: String; Optional; default = “current version of RubyGems“ DescriptionThe version of RubyGems used to create this gem. UsageNo usage ... it is set automatically when the gem is created. Goto Table of Contents specification_versionType: Integer; Optional; default = “Revision level of the RubyGems specification this gem conforms to.“ DescriptionThe revision level of the GemSpec specification that this gem conforms to. UsageNo usage ... it is set automatically when the gem is created. Goto Table of Contents summaryType: String; Required DescriptionA short description of the gem. Usagespec.summary = 'Ruby based make-like utility.' NotesThe summary is used to describe the gem in lists produced by the gem tool. See also description, which is less important. Goto Table of Contents test_filesType: Array; Optional; default = [] DescriptionA collection of unit test files. They will be loaded as unit tests when the user requests a gem to be unit tested. Usage
spec.test_files = Dir.glob('test/tc_*.rb') # (1)
spec.test_file = 'tests/test-suite.rb' # (2)
spec.test_files = ['tests/test-suite.rb'] # (3)
NotesExample (1) specifies that all files matching tc_*.rb in the test directory are unit test files. Example (2) shows that you can specify a test suite instead, which presumably loads individual test cases. This uses the shortcut method test_file=, and has the same effect as example (3). Goto Table of Contents versionType: String; Required DescriptionThe version of the gem. See RationalVersioningPolicy for some advice on specifying the version number for your gem. Usagespec.version = '0.4.1' NotesThe canonical way to represent versions in RubyGems is with the Gem::Version class. But the practical way to specify it in a gemspec is with a String. The version string must consist purely of numbers and periods. Goto Table of Contents |