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 the opportunity to customize your project’s Gem::Specification . Here’s the bare minimum to get going:


 Jeweler::Tasks.new do |gem|
   gem.name = "the-perfect-gem"
   gem.summary = "This gem is perfect"
   gem.email = "[email protected]"
   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 filled 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

Managing files

By default, jeweler includes any files git knows about that aren’t .gitignored. When you need finer control, it’s easy to match your project’s needs.

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


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

   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

You can set using dependencies or add_dependency.


 Jeweler::Tasks.new do |gem|
   # other configuration omitted
  gem.add_dependency('log4r', '>= 1.0.5')
 end

Alternate ways of configuring the gemspec

In the very first example, we demonstrated 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.