Class: Packages::SemVer
- Inherits:
-
Object
- Object
- Packages::SemVer
- Defined in:
- app/models/packages/sem_ver.rb
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
- .match(str, prefixed: false) ⇒ Object
- .match?(str, prefixed: false) ⇒ Boolean
- .parse(str, prefixed: false) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(major = 0, minor = 0, patch = 0, prerelease = nil, build = nil, prefixed: false) ⇒ SemVer
constructor
TODO: Move logic into the SemanticVersionable concern gitlab.com/gitlab-org/gitlab/-/issues/455670.
- #prefixed? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(major = 0, minor = 0, patch = 0, prerelease = nil, build = nil, prefixed: false) ⇒ SemVer
TODO: Move logic into the SemanticVersionable concern gitlab.com/gitlab-org/gitlab/-/issues/455670
9 10 11 12 13 14 15 16 |
# File 'app/models/packages/sem_ver.rb', line 9 def initialize(major = 0, minor = 0, patch = 0, prerelease = nil, build = nil, prefixed: false) @major = major @minor = minor @patch = patch @prerelease = prerelease @build = build @prefixed = prefixed end |
Instance Attribute Details
#build ⇒ Object
Returns the value of attribute build.
4 5 6 |
# File 'app/models/packages/sem_ver.rb', line 4 def build @build end |
#major ⇒ Object
Returns the value of attribute major.
4 5 6 |
# File 'app/models/packages/sem_ver.rb', line 4 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
4 5 6 |
# File 'app/models/packages/sem_ver.rb', line 4 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
4 5 6 |
# File 'app/models/packages/sem_ver.rb', line 4 def patch @patch end |
#prerelease ⇒ Object
Returns the value of attribute prerelease.
4 5 6 |
# File 'app/models/packages/sem_ver.rb', line 4 def prerelease @prerelease end |
Class Method Details
.match(str, prefixed: false) ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/models/packages/sem_ver.rb', line 39 def self.match(str, prefixed: false) return unless str&.start_with?('v') == prefixed str = str[1..] if prefixed Gitlab::Regex.semver_regex.match(str) end |
.match?(str, prefixed: false) ⇒ Boolean
47 48 49 |
# File 'app/models/packages/sem_ver.rb', line 47 def self.match?(str, prefixed: false) !match(str, prefixed: prefixed).nil? end |
.parse(str, prefixed: false) ⇒ Object
51 52 53 54 55 56 |
# File 'app/models/packages/sem_ver.rb', line 51 def self.parse(str, prefixed: false) m = match str, prefixed: prefixed return unless m new(m[1].to_i, m[2].to_i, m[3].to_i, m[4], m[5], prefixed: prefixed) end |
Instance Method Details
#==(other) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/models/packages/sem_ver.rb', line 22 def ==(other) self.class == other.class && self.major == other.major && self.minor == other.minor && self.patch == other.patch && self.prerelease == other.prerelease && self.build == other.build end |
#prefixed? ⇒ Boolean
18 19 20 |
# File 'app/models/packages/sem_ver.rb', line 18 def prefixed? @prefixed end |
#to_s ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/models/packages/sem_ver.rb', line 31 def to_s s = "#{prefixed? ? 'v' : ''}#{major || 0}.#{minor || 0}.#{patch || 0}" s += "-#{prerelease}" if prerelease s += "+#{build}" if build s end |