Class Library::Version
In: lib/library.rb
Parent: Object

see README for a detailed explanation of current, revision, and age essentially this class resents a version trio as in '1.2.0'

Methods
<=>    ===    inspect    new    next    next!    parse   
Attributes
:age  [R] 
:current  [R] 
:revision  [R] 
Included modules
Comparable
Public Class methods
new(current, revision=nil, age=nil)

versions may be initialized like

  Version.new 'foo.rb.1.0.0'
  Version.new '1.0.0'
  Version.new 1,0,0
# File lib/library.rb, line 55
    def initialize current, revision=nil, age=nil
      if String === current
	m = @@vpat.match(current)
	raise "BAD VERSION STRING #{current}" unless m and m[1]
	vs = m[1] 
	@current, @revision, @age = 
	  (vs.split }[\.,]}).map{|n| n.to_i}
      elsif Version === current
	@current, @revision, @age = 
	  [:current, :revision, :age].map{|m| current.send m}
      else
	@current, @revision, @age = 
	  [current, revision, age].map{|n| n.to_i}
      end

      @current ||= 0; @revision ||= 0; @age ||= 0

      raise 'REQUIRE : age <= current)' unless 
	@age <= @current
    end
parse(filename)
# File lib/library.rb, line 158
      def parse filename
	f = filename.to_s.clone
	v = Version.new(f) 
	f[}.#{v}$}] = ''
	[f, v]
      end
Public Instance methods
inspect()
# File lib/library.rb, line 76
    def inspect
      [current.to_s, revision.to_s, age.to_s].join '.'
    end
<=>(version)

a version is 'larger' than another iff

# File lib/library.rb, line 87
    def <=> version
      v = (String === version ? Version.new(version) : version)
      comp = current <=> v.current
      return comp unless comp == 0 
      comp = revision <=> v.revision
      return comp unless comp == 0 
      comp = age <=> v.age
      return comp unless comp == 0 
      return comp
    end
===(version)

returns wether this version will support another using rules from README eg.

    2.1.2 supports 0.1.0

since

  (2 - 2) <= 0
# File lib/library.rb, line 103
    def === version 
      v = (String === version ? Version.new(version) : version)
      comp = current <=> v.current
      case comp
	when -1
	  return false
	when 0
	  return true
	when 1
	  return ((current - age) <= v.current)
      end
    end
next!(implementation_changed = true, interface_changed = false, backwards_compatible = false)

uses rules from README to correctly increment version numbers modifying self in place

# File lib/library.rb, line 121
    def next! implementation_changed = true, 
	      interface_changed = false,  
              backwards_compatible = false

      mod = false

      if interface_changed
	mod = true
	@current += 1
	@revision = 0
	if backwards_compatible
	  @age += 1
	else
	  @age = 0
	end
      else
	if implementation_changed
	  mod = true
	  @revision += 1
	end
      end

      return (mod ? self : nil)
    end
next(implementation_changed = true, interface_changed = false, backwards_compatible = false)

uses rules from README to correctly increment version numbers

# File lib/library.rb, line 147
    def next implementation_changed = true, 
	     interface_changed = false,  
             backwards_compatible = false
      v = Version.new(self)
      v.next!  implementation_changed, 
	       interface_changed,  
	       backwards_compatible
      v
    end