Simple version-numbering encoding and helper methods
Ruby
Pull request Compare This branch is 10 commits ahead, 48 commits behind stouset:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
spec
.gitignore
History.rdoc
License.txt
README.rdoc
Rakefile
TODO.rdoc
VERSION
version.gemspec

README.rdoc

Version

Description

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

Features

  • Rake::VersionTask provides tasks for simple version bumping

  • Version smartly handles several versioning schemes, abstracting the details

Examples

Screencast

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'
Rake::VersionTask.new

You're all set up.

$ rake version:create VERSION=0.1.0 # => 0.1.0
$ 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.1a
$ rake version:bump                 # => 0.2.2
$ rake version:bump:major           # => 1.0.0
$ rake version:bump:minor           # => 1.0.1
$ cat VERSION                       # => 1.0.1

The VersionTask can automatically manage git tagging for you, too.

Rake::VersionTask.new do |task|
  task.with_git_tag = true
end

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

spec = Gem::Specification.new do |s|
  ...
end

Rake::VersionTask.new do |task|
  task.with_gemspec = spec
end

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
  is_versioned
end

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)       # => 1.3.0
v.bump!(:minor, true) # => 1.3
v.major = 2           # => 2.0
v.to_a                # => ['2', '0']

Binary

Version comes with a binary that lets you manage version numbering automatically.

$ version -v 0.1.0 create           # => 0.1.0
$ version                           # => 0.1.0
$ version bump                      # => 0.1.1
$ version bump minor                # => 0.2.0
$ version bump revision             # => 0.2.1
$ version bump major                # => 1.0.0
$ version bump minor                # => 1.0.1
$ cat VERSION                       # => 1.0.1

Full usage information available:

$ version -h

Most of the options the binary accepts can be provided in a .version file and will be applied each time the binary is called.

Install

[sudo] gem install version