RubyGems – multiple versions

RubyGems can support multiple versions of a single package installed simultaneously without breaking software

e.g.

$ gem list rake

*** LOCAL GEMS ***

rake (10.0.4, 0.9.6)

 If you had:

require ‘builder’

but needed to use an older version you’d use:

require ‘rubygems’

require_gem ‘builder’ “<1.0”

gem install –remote builder –version “< 1.0”

Here’s how to specify version constraints:

Exact version equal to v

” = v” 

Exact version not equal to v

” != v” 

Greater than v

” > v” 

Greater than or equal to v

” >= v” 

Less than v

” < v” 

Less than or equal to v

” <= v” 

Approximately greater than v

” ~> v” 

All pretty understandable apart from that last one. “Approximately greater than” lets you implement a “Rational Version Policy”. What’s this?

Simplifying, libraries change in 3 ways/categories:

1. implementation detail only – no effect on client software

2. new features – but client software written to an earlier version is still compatible

3. public interface of the library is changed so old software is no longer compatible

Some examples: assume you have a Stack class that supports a push and a pop method

Category 1 changes:

Switch from an array based implementation to a linked-list based implementation

Provide an automatic (and transparent) backing store for large stacks

Category 2 changes:

Add a depth method to return the current depth of the stack

Add a top method that returns the current top of stack (without changing the stack)

Change push so that it returns the item pushed (previously it had no usable return value)

Category 3 changes:

Changes pop so that it no longer returns a value (you must use top to get the top of the stack)

Rename the methods to push_item and pop_item

These are specified as follows:

major.minor.build

where Major => Category 3 change, Minor => Category 2, Build => Category 1

e.g. in the first example of rake above

10.0.4

http://onestepback.org/articles/rubygemsfacets/demomultipleversions.html

and

http://docs.rubygems.org/read/chapter/7

Leave a Reply

Your email address will not be published. Required fields are marked *