Simple version-numbering encoding and helper methods
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib Forgot quotes around commit message Aug 8, 2014
spec Cleanup, change around interpretation of prerelease bump May 2, 2011
.gitignore Modernize project structure (and make compatible with Travis) Nov 19, 2012
Gemfile Use HTTPS to connect to Rubygems Sep 24, 2014
History.rdoc History update to reflect actual version releases Feb 23, 2010
License.txt License under MIT Feb 5, 2010
README.rdoc Update README to show off `rake -T version` May 2, 2011
Rakefile Modernize project structure (and make compatible with Travis) Nov 19, 2012
VERSION Version bump to 1.0.0 May 10, 2011
version.gemspec Modernize project structure (and make compatible with Travis) Nov 19, 2012




Version is a simple wrapper around the concept of version-numbering schemes.


  • Rake::VersionTask provides tasks for simple version bumping

  • Version smartly handles several versioning schemes, abstracting the details



For a quick introduction, watch the screencast of my presentation at the Atlanta Ruby Users’ Group.

Rake Tasks

Version comes with a Rake::VersionTask that lets you manage version numbering automatically. Place the following in a Rakefile:

require 'rake/version_task'

You're all set up.

$ rake version:create VERSION=0.1.0 # => 0.1.0

Now `rake -T version` will tell you what all you can do.

$ version [master *$%]$ rake -T version
rake version                    # Print the current version number (0.1.0)
rake version:bump               # Bump to 0.1.1
rake version:bump:major         # Bump to 1.0.0
rake version:bump:minor         # Bump to 0.2.0
rake version:bump:pre           # Bump to 0.1.1a
rake version:bump:pre:major     # Bump to 1.0.0a
rake version:bump:pre:minor     # Bump to 0.2.0a
rake version:bump:pre:revision  # Bump to 0.1.1a
rake version:bump:revision      # Bump to 0.1.1
rake version:create             # Creates a version file with an optional VERSION parameter

$ rake version                      # => 0.1.0
$ rake version:bump                 # => 0.1.1
$ rake version:bump:minor           # => 0.2.0
$ rake version:bump:revision        # => 0.2.1
$ rake version:bump:pre             # => 0.2.2a
$ rake version:bump                 # => 0.2.2
$ rake version:bump:major           # => 1.0.0
$ rake version:bump:minor           # => 1.1.0
$ cat VERSION                       # => 1.1.0

The VersionTask can automatically manage git tagging for you, too. do |task|
  task.with_git_tag = true

And if you want the VersionTask to automatically emit updated gemspecs on version-bumps, use the with_gemspec flag.

spec = do |s|
end do |task|
  task.with_gemspec = spec

Version also supports a .yml VERSION file. See the VersionTask rdoc for details.

Library Versioning

Version lets you automatically keep an in-class VERSION constant in sync with the contents of the version file on disk. Version also provides a class-level current method which lets you get the current version without setting a class-level constant.

require 'version'

Version.current # => 1.0.1

class Foo

Foo::VERSION # => 1.0.1

The Version.current and Class::is_versioned methods both take a filename parameter if you use a different location for the VERSION file. See the Version.current rdoc for details.

Manipulation in Code

All the above functionality is performed behind-the-scenes by the Version library. It's simple to use, but I'll be surprised if there's much point beyond doing the legwork for the Rake task and class versioning.

v = "1.2.0".to_version
v.to_s                       # => 1.2.0
v.bump!                      # => 1.2.1
v.bump!(:major)              # => 2.0.0
v.bump!(:minor, false, true) # => 2.1
v.major = 3                  # => 3.0
v.to_a                       # => ['3', '0']


[sudo] gem install version