Roll  Roll::Version

[Validate]
Generated with WebRI Redfish 1.2.1

Version

VersionNumber is a simplified form of a Tuple class desgined specifically for dealing with version numbers.

Public Class Methods

[](*args) click to toggle source

Convenience alias for ::new.

    # File lib/roll/version.rb, line 17
17:     def [](*args)
18:       new(*args)
19:     end
constraint_lambda(constraint) click to toggle source

Parses a string constraint returning the operation as a lambda.

    # File lib/roll/version.rb, line 23
23:     def constraint_lambda(constraint)
24:       op, val = *parse_constraint(constraint)
25:       lambda{ |t| t.send(op, val) }
26:     end
new(*args) click to toggle source
    # File lib/roll/version.rb, line 51
51:     def initialize(*args)
52:       args = args.join('.').split(/\W+/)
53:       @tuple = args.collect { |i| i.to_i }
54:       #@tuple.extend(Comparable)
55:     end
parse_constraint(constraint) click to toggle source

Converts a constraint into an operator and value.

    # File lib/roll/version.rb, line 30
30:     def parse_constraint(constraint)
31:       constraint = constraint.strip
32:       re = %{^(=~|~>|<=|>=|==|=|<|>)?\s*(\d+(:?[-.]\d+)*)$}
33:       if md = re.match(constraint)
34:         if op = md[1]
35:           op = '=~' if op == '~>'
36:           op = '==' if op == '='
37:           val = new(*md[2].split(/\W+/))
38:         else
39:           op = '=='
40:           val = new(*constraint.split(/\W+/))
41:         end
42:       else
43:         raise ArgumentError, "invalid constraint"
44:       end
45:       return op, val
46:     end

Public Instance Methods

<=>(other) click to toggle source

“Spaceship” comparsion operator.

    # File lib/roll/version.rb, line 72
72:     def <=>(other)
73:       #other = other.to_t
74:       [@tuple.size, other.size].max.times do |i|
75:         c = @tuple[i] <=> other[i]
76:         return c if c != 0
77:       end
78:       0
79:     end
=~(other) click to toggle source

For pessimistic constraint (like ’~>’ in gems).

    # File lib/roll/version.rb, line 83
83:     def =~(other)
84:       #other = other.to_t
85:       upver = other.tuple.dup
86:       i = upver.index(0)
87:       i = upver.size unless i
88:       upver[i-1] += 1
89:       self >= other && self < upver
90:     end
[](i) click to toggle source

def inspect; to_s; end

    # File lib/roll/version.rb, line 66
66:     def [](i)
67:       @tuple.fetch(i,0)
68:     end
major() click to toggle source

Major is the first number in the version series.

    # File lib/roll/version.rb, line 94
94:     def major ; @tuple[0] ; end
method_missing(sym, *args, &blk) click to toggle source

Delegate to the array.

     # File lib/roll/version.rb, line 106
106:     def method_missing(sym, *args, &blk)
107:       @tuple.send(sym, *args, &blk) rescue super
108:     end
minor() click to toggle source

Minor is the second number in the version series.

    # File lib/roll/version.rb, line 98
98:     def minor ; @tuple[1] || 0 ; end
teeny() click to toggle source

Teeny is third number in the version series.

     # File lib/roll/version.rb, line 102
102:     def teeny ; @tuple[2] || 0 ; end
to_s() click to toggle source
    # File lib/roll/version.rb, line 59
59:     def to_s ; @tuple.join('.') ; end
to_str() click to toggle source

This is here only becuase File.join calls it instead of to_s.

    # File lib/roll/version.rb, line 62
62:     def to_str ; @tuple.join('.') ; end

Protected Instance Methods

tuple() click to toggle source
     # File lib/roll/version.rb, line 112
112:     def tuple ; @tuple ; end

Disabled; run with --debug to generate this.