Class: TravisCheckRubies::Version
- Inherits:
-
Object
- Object
- TravisCheckRubies::Version
- Includes:
- Comparable
- Defined in:
- lib/travis_check_rubies/version.rb
Instance Attribute Summary collapse
-
#pre ⇒ Object
readonly
Returns the value of attribute pre.
-
#str ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute str.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
-
#version_parts ⇒ Object
readonly
Returns the value of attribute version_parts.
Class Method Summary collapse
- .available ⇒ Object
- .convert(version_or_string) ⇒ Object
- .update(version, parts: 0..2, allow_pre: false, intermediary: true, exclude: [], conservative: false) ⇒ Object
- .updates(versions, **options) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #hash ⇒ Object
-
#initialize(str) ⇒ Version
constructor
A new instance of Version.
- #inspect ⇒ Object
- #match?(other, n) ⇒ Boolean
Constructor Details
#initialize(str) ⇒ Version
Returns a new instance of Version.
76 77 78 79 80 81 82 83 84 |
# File 'lib/travis_check_rubies/version.rb', line 76 def initialize(str) str = "#{str}" @str = str.sub(/^ruby-/, '') @variant = $1 if str.slice!(/-(clang|railsexpress)$/) @type = str.slice!(/^([^0-9\-]+)-?/) ? $1 : 'ruby' version_str = $1 if str.slice!(/^(\d+(?:\.\d+)*(?:-p\d+)?)(\.|-|$)/) @version_parts = version_str.scan(/\d+/).map(&:to_i) if version_str @pre = str unless str.empty? end |
Instance Attribute Details
#pre ⇒ Object (readonly)
Returns the value of attribute pre.
70 71 72 |
# File 'lib/travis_check_rubies/version.rb', line 70 def pre @pre end |
#str ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute str.
70 71 72 |
# File 'lib/travis_check_rubies/version.rb', line 70 def str @str end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
70 71 72 |
# File 'lib/travis_check_rubies/version.rb', line 70 def type @type end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
70 71 72 |
# File 'lib/travis_check_rubies/version.rb', line 70 def variant @variant end |
#version_parts ⇒ Object (readonly)
Returns the value of attribute version_parts.
70 71 72 |
# File 'lib/travis_check_rubies/version.rb', line 70 def version_parts @version_parts end |
Class Method Details
.available ⇒ Object
13 14 15 |
# File 'lib/travis_check_rubies/version.rb', line 13 def available @available ||= [TravisIndex, RvmIndex].map(&:new).map(&:version_strings).inject(:|).map{ |s| new(s) }.sort end |
.convert(version_or_string) ⇒ Object
9 10 11 |
# File 'lib/travis_check_rubies/version.rb', line 9 def convert(version_or_string) version_or_string.is_a?(self) ? version_or_string : new(version_or_string) end |
.update(version, parts: 0..2, allow_pre: false, intermediary: true, exclude: [], conservative: false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/travis_check_rubies/version.rb', line 17 def update(version, parts: 0..2, allow_pre: false, intermediary: true, exclude: [], conservative: false) version = convert(version) return unless version.version_parts parts = Array(parts) exclude = exclude.map{ |ev| convert(ev) } ordered = allow_pre ? available : available.partition(&:pre).inject(:+) candidates = ordered.select do |v| next unless v.version_parts next unless v.match?(version, parts.min) next unless v >= version next if !allow_pre && v.pre && !version.pre next if exclude.any?{ |ev| ev.match?(v, ev.version_parts.length) } true end.reverse updates = if intermediary candidates.group_by do |v| v.version_parts.take(parts.max) end.flat_map do |_, group| parts.map do |n| group.find{ |v| v.match?(version, n) } end end else parts.map do |n| candidates.find{ |v| v.match?(version, n) } end end updates.compact! updates.uniq! updates.sort! updates unless [version] == updates end |
.updates(versions, **options) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/travis_check_rubies/version.rb', line 54 def updates(versions, **) versions = versions.map{ |v| convert(v) } updates = {} has = Set.new versions.uniq.sort.reverse_each do |version| deduplicated = (update(version, ) || [version]).select{ |v| has.add?(v) } updates[version] = [version] == deduplicated ? nil : deduplicated end Hash[versions.map{ |v| [v, updates[v]] }] end |
Instance Method Details
#<=>(other) ⇒ Object
86 87 88 89 |
# File 'lib/travis_check_rubies/version.rb', line 86 def <=>(other) other = self.class.new(other) unless other.is_a?(self.class) compare_by <=> other.compare_by end |
#hash ⇒ Object
91 92 93 |
# File 'lib/travis_check_rubies/version.rb', line 91 def hash str.hash end |
#inspect ⇒ Object
100 101 102 |
# File 'lib/travis_check_rubies/version.rb', line 100 def inspect "#<#{self.class.name} #{str}>" end |
#match?(other, n) ⇒ Boolean
95 96 97 98 |
# File 'lib/travis_check_rubies/version.rb', line 95 def match?(other, n) other = self.class.new(other) unless other.is_a?(self.class) match_by(n) == other.match_by(n) end |