Class: VersionManager::ReleaseVersion
- Inherits:
-
Object
- Object
- VersionManager::ReleaseVersion
- Includes:
- Comparable
- Defined in:
- lib/version-manager/release_version.rb
Defined Under Namespace
Classes: IncorrentFormat
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
-
#special ⇒ Object
readonly
Returns the value of attribute special.
Class Method Summary collapse
Instance Method Summary collapse
- #-(other) ⇒ Object
- #<=>(other) ⇒ Object
- #bump(release_type) ⇒ Object
- #bump_major ⇒ Object
- #bump_minor ⇒ Object
- #bump_patch ⇒ Object
-
#initialize(*version_input) ⇒ ReleaseVersion
constructor
A new instance of ReleaseVersion.
- #short_version ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*version_input) ⇒ ReleaseVersion
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/version-manager/release_version.rb', line 12 def initialize(*version_input) version_components = Array(version_input.dup.flatten) if version_components.size == 1 version_components = version_components.first.scan(/(\d+)\.{1}(\d+)\.?(\d*)(?:--(\w+))?/).flatten raise ArgumentError, 'Incorrect version format' if version_components.all?(&:nil?) || version_components.empty? end @major, @minor, @patch = version_components[0..2].map(&:to_i) @special = version_components[3] recalculate_parts end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
65 66 67 |
# File 'lib/version-manager/release_version.rb', line 65 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
65 66 67 |
# File 'lib/version-manager/release_version.rb', line 65 def minor @minor end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
65 66 67 |
# File 'lib/version-manager/release_version.rb', line 65 def parts @parts end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
65 66 67 |
# File 'lib/version-manager/release_version.rb', line 65 def patch @patch end |
#special ⇒ Object (readonly)
Returns the value of attribute special.
65 66 67 |
# File 'lib/version-manager/release_version.rb', line 65 def special @special end |
Class Method Details
.valid?(version) ⇒ Boolean
59 60 61 62 63 |
# File 'lib/version-manager/release_version.rb', line 59 def self.valid?(version) new(version) && true rescue ArgumentError false end |
Instance Method Details
#-(other) ⇒ Object
38 39 40 |
# File 'lib/version-manager/release_version.rb', line 38 def -(other) self.class.new(parts.zip(other.parts).map { |x, y| x - y }) end |
#<=>(other) ⇒ Object
32 33 34 35 36 |
# File 'lib/version-manager/release_version.rb', line 32 def <=>(other) parts.zip(other.parts) .map { |this, other_part| this <=> other_part } .find { |res| res != 0 } || 0 end |
#bump(release_type) ⇒ Object
42 43 44 45 |
# File 'lib/version-manager/release_version.rb', line 42 def bump(release_type) raise ArgumentError, 'Unknown release type' unless i(major minor patch).include?(release_type.to_sym) public_send("bump_#{release_type}") end |
#bump_major ⇒ Object
47 48 49 |
# File 'lib/version-manager/release_version.rb', line 47 def bump_major self.class.new(@major + 1, 0, 0) end |
#bump_minor ⇒ Object
51 52 53 |
# File 'lib/version-manager/release_version.rb', line 51 def bump_minor self.class.new(@major, @minor + 1, 0) end |
#bump_patch ⇒ Object
55 56 57 |
# File 'lib/version-manager/release_version.rb', line 55 def bump_patch self.class.new(@major, @minor, @patch + 1) end |
#short_version ⇒ Object
28 29 30 |
# File 'lib/version-manager/release_version.rb', line 28 def short_version [major, minor].map(&:to_i).join('.') end |
#to_s ⇒ Object
23 24 25 26 |
# File 'lib/version-manager/release_version.rb', line 23 def to_s res = parts.map(&:to_i).join('.') [res, special].compact.join('--') end |