Skip to content

rodrei/versionable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Versionable

This Gem provides a way to work with semantic version numbers in ActiveRecord models.

Installation

Add the following line to your Gemfile and run the bundle command to install it.

  gem "versionable"

Usage

Call version_field from within an ActiveRecord model class and pass the name of the field to be used as a version number. This field must be of type Float.

  class Release < ActiveRecord::Base
    version_field :version
  end

Versionable now will setup a wrapper around the version field.

  • Assigning and retrieving can be done as if the version field were a string:
  release.version = '1.2.34'
  # => "1.2.34"

  release.version
  # => "1.2.34"
  • It is possible to access the value as it’s stored in the database through raw_#{version_field_name}.
  release.raw_version
  # => 0.01002034

How does it work?

Versionable internally stores the version number as float using the following simple rule:

Version X.Y.Z is saved internally as the float value x.xxyyyzzz.

So version 1.2.3 is stored as 0.01002003.

This allows to do SQL searches using the ordering clause.

About

Ruby Gem to manage version numbers in ActiveRecord

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages