Class: Groundskeeper::SemanticVersion
- Inherits:
-
Object
- Object
- Groundskeeper::SemanticVersion
- Defined in:
- lib/groundskeeper/semantic_version.rb
Overview
Encapsulates semantic version manipulation and comparison.
Constant Summary collapse
- MAJOR =
"major"
- MINOR =
"minor"
- PATCH =
"patch"
- SEMANTIC_RELEASE_TYPE =
{ M: MAJOR, m: MINOR, p: PATCH }.freeze
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
Class Method Summary collapse
-
.build(version) ⇒ Object
:nocov:.
Instance Method Summary collapse
- #>(other) ⇒ Object
- #bump(release_type) ⇒ Object
-
#initialize(version) ⇒ SemanticVersion
constructor
:nocov:.
Constructor Details
#initialize(version) ⇒ SemanticVersion
:nocov:
21 22 23 |
# File 'lib/groundskeeper/semantic_version.rb', line 21 def initialize(version) @major, @minor, @patch = version.split(".").map(&:to_i) end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
11 12 13 |
# File 'lib/groundskeeper/semantic_version.rb', line 11 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
11 12 13 |
# File 'lib/groundskeeper/semantic_version.rb', line 11 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
11 12 13 |
# File 'lib/groundskeeper/semantic_version.rb', line 11 def patch @patch end |
Class Method Details
.build(version) ⇒ Object
:nocov:
14 15 16 17 18 |
# File 'lib/groundskeeper/semantic_version.rb', line 14 def self.build(version) return version if version.is_a?(SemanticVersion) new(version) end |
Instance Method Details
#>(other) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/groundskeeper/semantic_version.rb', line 36 def >(other) other_version = SemanticVersion.build(other) other_major = other_version.major return true if major > other_major return false unless major == other_major other_minor = other_version.minor return true if minor > other_minor minor == other_minor && patch > other_version.patch end |
#bump(release_type) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/groundskeeper/semantic_version.rb', line 25 def bump(release_type) case SEMANTIC_RELEASE_TYPE[release_type.to_sym] when MAJOR "#{major + 1}.0.0" when MINOR "#{major}.#{minor + 1}.0" when PATCH "#{major}.#{minor}.#{patch + 1}" end end |