Skip to content

Customizing your project's gem specification

technicalpickles edited this page Aug 22, 2010 · 9 revisions

When you instantiate your Jeweler::Tasks, you have opportunity to customize your projects Gem::Specification . Here the bare minimum to get going:


 Jeweler::Tasks.new do |gem|
   gem.name = "the-perfect-gem"
   gem.summary = "This gem is perfect"
   gem.email = "josh@technicalpickles.com"
   gem.homepage = "http://github.com/technicalpickles/the-perfect-gem"
   gem.authors = ["Josh Nichols"]
 end

In this example, the block variable gem is a brand new Gem::Specification that has been filed in with some defaults:

  • files is set to a FileList containing some standard directories for a gem (ie the contents of bin, lib, rails, generators)
  • extra_rdoc_files is set to a FileList containing README, ChangeLog, and LICENSE files.
  • test_files is set to a FileList containing the standard test directories
  • has_rdoc is set to true
  • executables is populated from the bin directory

If you are familiar with Gem::Specification, you are probably wondering where version is set. Jeweler manages the

Managing files

The defaults Jeweler sets for the files should be sufficient for most projects. When they are not, it’s easy to match your projects needs.

If you need to only add or remove files from the defaults, you can easily do so, because enhances the Gem::Specification to use FileLists as necessary. This means you can do something like:


 Jeweler::Tasks.new do |gem|
   # other configuration omitted

   # The default doesn't match files that start .
   gem.files.include %w(lib/jeweler/templates/.document lib/jeweler/templates/.gitignore)

    # Lots of large files in test/data... don't include them to keep gem size down
    gem.files.exclude 'test/data/**/*'
    gem.test_files.exclude 'test/data/**/*'
 end

Sometimes this might be enough. You are able to just set files, test_files, etc to some value of your choosing:


 Jeweler::Tasks.new do |gem|
   # other configuration omitted

   # we like to keep our gem slim
   gem.files = FileList['lib/**/*.rb']
   gem.test_files = []
 end

Managing dependencies

Alternate ways of configuring the gemspec

In the very first example, we showed using a block to define the gemspec. You can alternatively make a spec, and pass it to Jeweler::Tasks.


 spec = Gem::Specification.new do |s|
   # omitted
 end
 Jeweler::Tasks.new(spec)

The spec will be filled in with Jeweler defaults, but it should not override anything that you’ve already set.

Clone this wiki locally