Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simple version-numbering encoding and helper methods

tree: 9f65c68a69

Fetching latest commit…

Cannot retrieve the latest commit at this time

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

  • Version adds versioning to your Rails3 application

Installation

Using Bundler?

Add the following to your Gemfile

gem 'version'

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

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

VersionTask automatically manages git tagging if git is detected. To disable automatic tagging:

Rake::VersionTask.new do |task|
  task.with_git_tag = false
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

Version.set(Foo)

or

class Foo

  Version.set(self)

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.

Rails3 Versioning

Version adds a VERSION to the applications namespace should you need to access the version information from within the application.

So if your config/environment.rb looks like this;

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Silverbug::Application.initialize!

You can retrieve the current running version with;

Silverbug::VERSION

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 = Version.new("1.2.0")
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']

Install

[sudo] gem install version
Something went wrong with that request. Please try again.