Class: Builderator::Control::Version
- Inherits:
-
Object
- Object
- Builderator::Control::Version
- Includes:
- Auto, Bump, Comparable
- Defined in:
- lib/builderator/control/version.rb,
lib/builderator/control/version/git.rb,
lib/builderator/control/version/scm.rb,
lib/builderator/control/version/auto.rb,
lib/builderator/control/version/bump.rb,
lib/builderator/control/version/comparable.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Auto, Bump, Comparable, Git, SCM
Constant Summary collapse
- FORMAT =
/(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?<prerelease>-(?<prerelease_name>[A-Za-z0-9]+)\.(?<prerelease_iteration>\d+))?(?:\+build\.(?<build>\d+))?$/- DEFAULT_PRERELEASE_NAME =
'alpha'.freeze
- RELEASE_TYPES =
Order of precedence for release types
{ 'major' => 0, 'major-prerelease' => 5, 'minor' => 10, 'minor-prerelease' => 15, 'patch' => 20, 'patch-prerelease' => 25, 'release' => 30, 'prerelease' => 35, 'build' => 40 }
Constants included from Auto
Auto::DEFAULT_TYPE, Auto::MESSAGE_KEYWORDS
Instance Attribute Summary collapse
-
#build ⇒ Object
Returns the value of attribute build.
-
#is_prerelease ⇒ Object
Returns the value of attribute is_prerelease.
-
#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_iteration ⇒ Object
Returns the value of attribute prerelease_iteration.
-
#prerelease_name ⇒ Object
Returns the value of attribute prerelease_name.
-
#ref ⇒ Object
Returns the value of attribute ref.
Class Method Summary collapse
-
.bump(type = nil, prerelease_name = nil) ⇒ Object
Alias ‘bump` to the current version.
- .current ⇒ Object
-
.from_string(arg, options = {}) ⇒ Object
Parse a SemVer string into a Version.
- .set_config_version ⇒ Object
- .write ⇒ Object
Instance Method Summary collapse
-
#initialize(major, minor, patch, build = nil, **options) ⇒ Version
constructor
A new instance of Version.
-
#prerelease(name = nil) ⇒ Object
Create or bump a new prerelease train.
- #to_s ⇒ Object
- #write ⇒ Object
Methods included from Comparable
Methods included from Bump
Methods included from Auto
Constructor Details
#initialize(major, minor, patch, build = nil, **options) ⇒ Version
Returns a new instance of Version.
83 84 85 86 87 88 89 90 |
# File 'lib/builderator/control/version.rb', line 83 def initialize(major, minor, patch, build = nil, **) @major = major.to_i @minor = minor.to_i @patch = patch.to_i @build = build.to_i unless build.nil? @ref = [:ref] end |
Instance Attribute Details
#build ⇒ Object
Returns the value of attribute build.
106 107 108 |
# File 'lib/builderator/control/version.rb', line 106 def build @build end |
#is_prerelease ⇒ Object
Returns the value of attribute is_prerelease.
102 103 104 |
# File 'lib/builderator/control/version.rb', line 102 def is_prerelease @is_prerelease end |
#major ⇒ Object
Returns the value of attribute major.
98 99 100 |
# File 'lib/builderator/control/version.rb', line 98 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
99 100 101 |
# File 'lib/builderator/control/version.rb', line 99 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
100 101 102 |
# File 'lib/builderator/control/version.rb', line 100 def patch @patch end |
#prerelease_iteration ⇒ Object
Returns the value of attribute prerelease_iteration.
104 105 106 |
# File 'lib/builderator/control/version.rb', line 104 def prerelease_iteration @prerelease_iteration end |
#prerelease_name ⇒ Object
Returns the value of attribute prerelease_name.
103 104 105 |
# File 'lib/builderator/control/version.rb', line 103 def prerelease_name @prerelease_name end |
#ref ⇒ Object
Returns the value of attribute ref.
96 97 98 |
# File 'lib/builderator/control/version.rb', line 96 def ref @ref end |
Class Method Details
.bump(type = nil, prerelease_name = nil) ⇒ Object
Alias ‘bump` to the current version
59 60 61 62 63 64 65 66 |
# File 'lib/builderator/control/version.rb', line 59 def bump(type = nil, prerelease_name = nil) @current = current.clone current.bump(type, prerelease_name) SCM. << current current end |
.current ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/builderator/control/version.rb', line 33 def current @current ||= SCM..last if @current.nil? && Util.relative_path('VERSION').exist? @current = Version.from_string(Util.relative_path('VERSION').read) end if @current.nil? fail 'No current version found! Create a VERSION file or set a version tag in your SCM.' end @current end |
.from_string(arg, options = {}) ⇒ Object
Parse a SemVer string into a Version
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/builderator/control/version.rb', line 69 def from_string(arg, = {}) matchdata = arg.match(FORMAT) return nil if matchdata.nil? new(matchdata[:major], matchdata[:minor], matchdata[:patch], matchdata[:build], ).tap do |version| version.is_prerelease = !matchdata[:prerelease].nil? if version.is_prerelease version.prerelease_name = matchdata[:prerelease_name] version.prerelease_iteration = matchdata[:prerelease_iteration].to_i end end end |
.set_config_version ⇒ Object
47 48 49 50 |
# File 'lib/builderator/control/version.rb', line 47 def set_config_version Config.defaults.version = current.to_s Config.recompile end |
.write ⇒ Object
52 53 54 |
# File 'lib/builderator/control/version.rb', line 52 def write current.write end |
Instance Method Details
#prerelease(name = nil) ⇒ Object
Create or bump a new prerelease train
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/builderator/control/version.rb', line 109 def prerelease(name = nil) self.build = nil ## Reset the build counter ## Increment current prerelease train if is_prerelease && (name.nil? || name == prerelease_name) self.prerelease_iteration += 1 return self end ## New prerelease train self.is_prerelease = true self.prerelease_name = name.nil? ? DEFAULT_PRERELEASE_NAME : name self.prerelease_iteration = 0 self end |
#to_s ⇒ Object
130 131 132 133 134 135 |
# File 'lib/builderator/control/version.rb', line 130 def to_s string = [major, minor, patch].join('.') string << "-#{prerelease_name}.#{prerelease_iteration}" if is_prerelease string << "+build.#{build}" unless build.nil? string end |
#write ⇒ Object
126 127 128 |
# File 'lib/builderator/control/version.rb', line 126 def write Util.relative_path('VERSION').write(to_s) end |