Class: Roll::Version
Overview
Version
VersionNumber is a simplified form of a Tuple class desgined specifically for dealing with version numbers.
Class Method Summary collapse
-
.[](*args) ⇒ Object
Convenience alias for ::new.
-
.constraint_lambda(constraint) ⇒ Object
Parses a string constraint returning the operation as a lambda.
-
.parse_constraint(constraint) ⇒ Object
Converts a constraint into an operator and value.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
“Spaceship” comparsion operator.
-
#=~(other) ⇒ Object
For pessimistic constraint (like ‘~>’ in gems).
-
#[](i) ⇒ Object
def inspect; to_s; end.
-
#major ⇒ Object
Major is the first number in the version series.
-
#method_missing(sym, *args, &blk) ⇒ Object
Delegate to the array.
-
#minor ⇒ Object
Minor is the second number in the version series.
-
#teeny ⇒ Object
Teeny is third number in the version series.
- #to_s ⇒ Object
-
#to_str ⇒ Object
This is here only becuase File.join calls it instead of to_s.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &blk) ⇒ Object
Delegate to the array.
106 107 108 |
# File 'lib/roll/version.rb', line 106 def method_missing(sym, *args, &blk) @tuple.send(sym, *args, &blk) rescue super end |
Class Method Details
.[](*args) ⇒ Object
Convenience alias for ::new.
17 18 19 |
# File 'lib/roll/version.rb', line 17 def [](*args) new(*args) end |
.constraint_lambda(constraint) ⇒ Object
Parses a string constraint returning the operation as a lambda.
23 24 25 26 |
# File 'lib/roll/version.rb', line 23 def constraint_lambda(constraint) op, val = *parse_constraint(constraint) lambda{ |t| t.send(op, val) } end |
.parse_constraint(constraint) ⇒ Object
Converts a constraint into an operator and value.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/roll/version.rb', line 30 def parse_constraint(constraint) constraint = constraint.strip re = %r{^(=~|~>|<=|>=|==|=|<|>)?\s*(\d+(:?[-.]\d+)*)$} if md = re.match(constraint) if op = md[1] op = '=~' if op == '~>' op = '==' if op == '=' val = new(*md[2].split(/\W+/)) else op = '==' val = new(*constraint.split(/\W+/)) end else raise ArgumentError, "invalid constraint" end return op, val end |
Instance Method Details
#<=>(other) ⇒ Object
“Spaceship” comparsion operator.
72 73 74 75 76 77 78 79 |
# File 'lib/roll/version.rb', line 72 def <=>(other) #other = other.to_t [@tuple.size, other.size].max.times do |i| c = @tuple[i] <=> other[i] return c if c != 0 end 0 end |
#=~(other) ⇒ Object
For pessimistic constraint (like ‘~>’ in gems).
83 84 85 86 87 88 89 90 |
# File 'lib/roll/version.rb', line 83 def =~(other) #other = other.to_t upver = other.tuple.dup i = upver.index(0) i = upver.size unless i upver[i-1] += 1 self >= other && self < upver end |
#[](i) ⇒ Object
def inspect; to_s; end
66 67 68 |
# File 'lib/roll/version.rb', line 66 def [](i) @tuple.fetch(i,0) end |
#major ⇒ Object
Major is the first number in the version series.
94 |
# File 'lib/roll/version.rb', line 94 def major ; @tuple[0] ; end |
#minor ⇒ Object
Minor is the second number in the version series.
98 |
# File 'lib/roll/version.rb', line 98 def minor ; @tuple[1] || 0 ; end |
#teeny ⇒ Object
Teeny is third number in the version series.
102 |
# File 'lib/roll/version.rb', line 102 def teeny ; @tuple[2] || 0 ; end |
#to_s ⇒ Object
59 |
# File 'lib/roll/version.rb', line 59 def to_s ; @tuple.join('.') ; end |
#to_str ⇒ Object
This is here only becuase File.join calls it instead of to_s.
62 |
# File 'lib/roll/version.rb', line 62 def to_str ; @tuple.join('.') ; end |