Class: VersionBoss::Semver::IncrementableVersion
- Defined in:
- lib/version_boss/semver/incrementable_version.rb
Overview
A Semver Version with additional constraints on the pre-release part of the version
An IncrementableVersion is valid if one of the two following conditions is met:
- The pre-release part is empty
- The pre-release part is composed of two dot-separated identifiers:
- the first being a String representing the pre-release type (e.g. 'alpha', 'beta', etc.). The default pre-release type is 'pre'
- the second being an Integer representing the pre-release sequence number (starting at 1)
Valid versions with pre-release parts: 1.2.3-alpha.1
, 1.2.3-beta.2
, 1.2.3-pre.3
Constant Summary collapse
- DEFAULT_PRE_TYPE =
The default pre-release identifier
'pre'
Instance Attribute Summary
Attributes inherited from Version
#build_metadata, #major, #minor, #patch, #pre_release, #pre_release_identifiers, #version
Instance Method Summary collapse
-
#next_major(pre: false, pre_type: DEFAULT_PRE_TYPE, build_metadata: nil) ⇒ IncrementableVersion
Increment the major version.
-
#next_minor(pre: false, pre_type: DEFAULT_PRE_TYPE, build_metadata: nil) ⇒ IncrementableVersion
Increment the minor version.
-
#next_patch(pre: false, pre_type: DEFAULT_PRE_TYPE, build_metadata: nil) ⇒ IncrementableVersion
Increment the patch version.
-
#next_pre(pre_type: nil, build_metadata: nil) ⇒ IncrementableVersion
Increment the pre_release part of the version.
-
#next_release(build_metadata: nil) ⇒ IncrementableVersion
Drop the pre-release part of the version.
-
#pre_number ⇒ Integer
The pre-release sequence number.
-
#pre_type ⇒ String
The pre-release type (for example, 'alpha', 'beta', 'pre', etc.).
-
#valid? ⇒ Boolean
Create a new IncrementableVersion object.
Methods inherited from Version
#<=>, #==, #initialize, #to_s
Constructor Details
This class inherits a constructor from VersionBoss::Semver::Version
Instance Method Details
#next_major(pre: false, pre_type: DEFAULT_PRE_TYPE, build_metadata: nil) ⇒ IncrementableVersion
Increment the major version
48 49 50 51 52 53 54 |
# File 'lib/version_boss/semver/incrementable_version.rb', line 48 def next_major(pre: false, pre_type: DEFAULT_PRE_TYPE, build_metadata: nil) version_string = "#{major.to_i + 1}.0.0" version_string += "-#{pre_type}.1" if pre = self. if .nil? version_string += "+#{}" unless .empty? IncrementableVersion.new(version_string) end |
#next_minor(pre: false, pre_type: DEFAULT_PRE_TYPE, build_metadata: nil) ⇒ IncrementableVersion
Increment the minor version
63 64 65 66 67 68 69 |
# File 'lib/version_boss/semver/incrementable_version.rb', line 63 def next_minor(pre: false, pre_type: DEFAULT_PRE_TYPE, build_metadata: nil) version_string = "#{major}.#{minor.to_i + 1}.0" version_string += "-#{pre_type}.1" if pre = self. if .nil? version_string += "+#{}" unless .empty? IncrementableVersion.new(version_string) end |
#next_patch(pre: false, pre_type: DEFAULT_PRE_TYPE, build_metadata: nil) ⇒ IncrementableVersion
Increment the patch version
78 79 80 81 82 83 84 |
# File 'lib/version_boss/semver/incrementable_version.rb', line 78 def next_patch(pre: false, pre_type: DEFAULT_PRE_TYPE, build_metadata: nil) version_string = "#{major}.#{minor}.#{patch.to_i + 1}" version_string += "-#{pre_type}.1" if pre = self. if .nil? version_string += "+#{}" unless .empty? IncrementableVersion.new(version_string) end |
#next_pre(pre_type: nil, build_metadata: nil) ⇒ IncrementableVersion
Increment the pre_release part of the version
93 94 95 96 97 98 99 100 |
# File 'lib/version_boss/semver/incrementable_version.rb', line 93 def next_pre(pre_type: nil, build_metadata: nil) assert_is_a_pre_release_version version_string = "#{major}.#{minor}.#{patch}" version_string += next_pre_part(pre_type) ||= self. version_string += "+#{}" unless .empty? IncrementableVersion.new(version_string) end |
#next_release(build_metadata: nil) ⇒ IncrementableVersion
Drop the pre-release part of the version
110 111 112 113 114 115 116 |
# File 'lib/version_boss/semver/incrementable_version.rb', line 110 def next_release(build_metadata: nil) assert_is_a_pre_release_version version_string = "#{major}.#{minor}.#{patch}" ||= self. version_string += "+#{}" unless .empty? IncrementableVersion.new(version_string) end |
#pre_number ⇒ Integer
The pre-release sequence number
The pre-release sequence number starts at 1 for each pre-release type.
138 139 140 |
# File 'lib/version_boss/semver/incrementable_version.rb', line 138 def pre_number pre_release_identifiers[1] end |
#pre_type ⇒ String
The pre-release type (for example, 'alpha', 'beta', 'pre', etc.)
125 126 127 |
# File 'lib/version_boss/semver/incrementable_version.rb', line 125 def pre_type pre_release_identifiers[0] end |
#valid? ⇒ Boolean
Create a new IncrementableVersion object
34 35 36 |
# File 'lib/version_boss/semver/incrementable_version.rb', line 34 def valid? super && (pre_release.empty? || (pre_release_identifiers.size == 2 && pre_number.is_a?(Integer))) end |