Class: VersionBoss::Gem::IncrementableVersion
- Defined in:
- lib/version_boss/gem/incrementable_version.rb
Overview
A VersionBoss::Semver with additional constraints on the pre-release part of the version
A 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
#major, #minor, #patch, #pre_release, #pre_release_identifiers, #version
Instance Method Summary collapse
-
#next_major(pre: false, pre_type: DEFAULT_PRE_TYPE) ⇒ IncrementableVersion
Increment the major version.
-
#next_minor(pre: false, pre_type: DEFAULT_PRE_TYPE) ⇒ IncrementableVersion
Increment the minor version.
-
#next_patch(pre: false, pre_type: DEFAULT_PRE_TYPE) ⇒ IncrementableVersion
Increment the patch version.
-
#next_pre(pre_type: nil) ⇒ IncrementableVersion
Increment the pre_release part of the version.
-
#next_release ⇒ IncrementableVersion
Drop the pre-release part of the version.
-
#pre_number ⇒ Integer
The pre-release sequence number.
-
#pre_number_prefix ⇒ String
The pre-release sequence number.
-
#pre_type ⇒ String
The pre-release type (for example, 'alpha', 'beta', 'pre', etc.).
-
#pre_type_prefix ⇒ '.', ''
Returns the prefix of the pre-release type.
-
#valid? ⇒ Boolean
Create a new IncrementableVersion object.
Methods inherited from Version
#<=>, #==, #initialize, #to_s
Constructor Details
This class inherits a constructor from VersionBoss::Gem::Version
Instance Method Details
#next_major(pre: false, pre_type: DEFAULT_PRE_TYPE) ⇒ IncrementableVersion
Increment the major version
48 49 50 51 52 |
# File 'lib/version_boss/gem/incrementable_version.rb', line 48 def next_major(pre: false, pre_type: DEFAULT_PRE_TYPE) version_string = "#{major.to_i + 1}.0.0" version_string += ".#{pre_type}1" if pre IncrementableVersion.new(version_string) end |
#next_minor(pre: false, pre_type: DEFAULT_PRE_TYPE) ⇒ IncrementableVersion
Increment the minor version
62 63 64 65 66 |
# File 'lib/version_boss/gem/incrementable_version.rb', line 62 def next_minor(pre: false, pre_type: DEFAULT_PRE_TYPE) version_string = "#{major}.#{minor.to_i + 1}.0" version_string += ".#{pre_type}1" if pre IncrementableVersion.new(version_string) end |
#next_patch(pre: false, pre_type: DEFAULT_PRE_TYPE) ⇒ IncrementableVersion
Increment the patch version
76 77 78 79 80 |
# File 'lib/version_boss/gem/incrementable_version.rb', line 76 def next_patch(pre: false, pre_type: DEFAULT_PRE_TYPE) version_string = "#{major}.#{minor}.#{patch.to_i + 1}" version_string += ".#{pre_type}1" if pre IncrementableVersion.new(version_string) end |
#next_pre(pre_type: nil) ⇒ IncrementableVersion
Increment the pre_release part of the version
89 90 91 92 93 94 |
# File 'lib/version_boss/gem/incrementable_version.rb', line 89 def next_pre(pre_type: nil) assert_is_a_pre_release_version version_string = "#{major}.#{minor}.#{patch}" version_string += next_pre_part(pre_type) IncrementableVersion.new(version_string) end |
#next_release ⇒ IncrementableVersion
Drop the pre-release part of the version
104 105 106 107 108 |
# File 'lib/version_boss/gem/incrementable_version.rb', line 104 def next_release assert_is_a_pre_release_version version_string = "#{major}.#{minor}.#{patch}" 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.
147 148 149 |
# File 'lib/version_boss/gem/incrementable_version.rb', line 147 def pre_number pre_release_identifiers[1].identifier end |
#pre_number_prefix ⇒ String
The pre-release sequence number
The pre-release identifier can optionally prefix the pre-release sequence number with a period.
161 162 163 |
# File 'lib/version_boss/gem/incrementable_version.rb', line 161 def pre_number_prefix pre_release_identifiers[1].prefix end |
#pre_type ⇒ String
The pre-release type (for example, 'alpha', 'beta', 'pre', etc.)
117 118 119 |
# File 'lib/version_boss/gem/incrementable_version.rb', line 117 def pre_type pre_release_identifiers[0].identifier end |
#pre_type_prefix ⇒ '.', ''
Returns the prefix of the pre-release type
Ruby Gem versions can optionally prefix the pre-release type with a period.
Semver requires a hyphen prefix.
134 135 136 |
# File 'lib/version_boss/gem/incrementable_version.rb', line 134 def pre_type_prefix pre_release_identifiers[0].prefix end |
#valid? ⇒ Boolean
Create a new IncrementableVersion object
33 34 35 |
# File 'lib/version_boss/gem/incrementable_version.rb', line 33 def valid? super && (pre_release.empty? || (pre_release_identifiers.size == 2 && pre_number.is_a?(Integer))) end |