Class: Dependabot::SemVersion2
- Inherits:
-
Object
- Object
- Dependabot::SemVersion2
- Extended by:
- T::Helpers, T::Sig
- Includes:
- Comparable
- Defined in:
- lib/dependabot/sem_version2.rb
Constant Summary collapse
- SEMVER2_REGEX =
/^ (0|[1-9]\d*)\. # major (0|[1-9]\d*)\. # minor (0|[1-9]\d*) # patch (?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))? # pre release (?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))? # build metadata $/x
Instance Attribute Summary collapse
-
#build ⇒ Object
Returns the value of attribute build.
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#patch ⇒ Object
Returns the value of attribute patch.
-
#prerelease ⇒ Object
Returns the value of attribute prerelease.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(version) ⇒ SemVersion2
constructor
A new instance of SemVersion2.
- #inspect ⇒ Object
- #prerelease? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ SemVersion2
Returns a new instance of SemVersion2.
38 39 40 41 42 43 44 45 |
# File 'lib/dependabot/sem_version2.rb', line 38 def initialize(version) tokens = parse(version) @major = T.let(T.must(tokens[:major]), String) @minor = T.let(T.must(tokens[:minor]), String) @patch = T.let(T.must(tokens[:patch]), String) @build = T.let(tokens[:build], T.nilable(String)) @prerelease = T.let(tokens[:prerelease], T.nilable(String)) end |
Instance Attribute Details
#build ⇒ Object
Returns the value of attribute build.
32 33 34 |
# File 'lib/dependabot/sem_version2.rb', line 32 def build @build end |
#major ⇒ Object
Returns the value of attribute major.
23 24 25 |
# File 'lib/dependabot/sem_version2.rb', line 23 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
26 27 28 |
# File 'lib/dependabot/sem_version2.rb', line 26 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
29 30 31 |
# File 'lib/dependabot/sem_version2.rb', line 29 def patch @patch end |
#prerelease ⇒ Object
Returns the value of attribute prerelease.
35 36 37 |
# File 'lib/dependabot/sem_version2.rb', line 35 def prerelease @prerelease end |
Class Method Details
.correct?(version) ⇒ Boolean
85 86 87 88 89 |
# File 'lib/dependabot/sem_version2.rb', line 85 def self.correct?(version) return false if version.nil? version.match?(SEMVER2_REGEX) end |
Instance Method Details
#<=>(other) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dependabot/sem_version2.rb', line 71 def <=>(other) result = major.to_i <=> other.major.to_i return result unless result.zero? result = minor.to_i <=> other.minor.to_i return result unless result.zero? result = patch.to_i <=> other.patch.to_i return result unless result.zero? compare_prereleases(prerelease, other.prerelease) end |
#eql?(other) ⇒ Boolean
66 67 68 |
# File 'lib/dependabot/sem_version2.rb', line 66 def eql?(other) other.is_a?(self.class) && to_s == other.to_s end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/dependabot/sem_version2.rb', line 61 def inspect "#<#{self.class} #{self}>" end |
#prerelease? ⇒ Boolean
48 49 50 |
# File 'lib/dependabot/sem_version2.rb', line 48 def prerelease? !!prerelease end |
#to_s ⇒ Object
53 54 55 56 57 58 |
# File 'lib/dependabot/sem_version2.rb', line 53 def to_s value = [major, minor, patch].join(".") value += "-#{prerelease}" if prerelease value += "+#{build}" if build value end |