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
bumpto 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.
73 74 75 76 77 78 79 80 |
# File 'lib/builderator/control/version.rb', line 73 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.
96 97 98 |
# File 'lib/builderator/control/version.rb', line 96 def build @build end |
#is_prerelease ⇒ Object
Returns the value of attribute is_prerelease.
92 93 94 |
# File 'lib/builderator/control/version.rb', line 92 def is_prerelease @is_prerelease end |
#major ⇒ Object
Returns the value of attribute major.
88 89 90 |
# File 'lib/builderator/control/version.rb', line 88 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
89 90 91 |
# File 'lib/builderator/control/version.rb', line 89 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
90 91 92 |
# File 'lib/builderator/control/version.rb', line 90 def patch @patch end |
#prerelease_iteration ⇒ Object
Returns the value of attribute prerelease_iteration.
94 95 96 |
# File 'lib/builderator/control/version.rb', line 94 def prerelease_iteration @prerelease_iteration end |
#prerelease_name ⇒ Object
Returns the value of attribute prerelease_name.
93 94 95 |
# File 'lib/builderator/control/version.rb', line 93 def prerelease_name @prerelease_name end |
#ref ⇒ Object
Returns the value of attribute ref.
86 87 88 |
# File 'lib/builderator/control/version.rb', line 86 def ref @ref end |
Class Method Details
.bump(type = nil, prerelease_name = nil) ⇒ Object
Alias bump to the current version
49 50 51 52 53 54 55 56 |
# File 'lib/builderator/control/version.rb', line 49 def bump(type = nil, prerelease_name = nil) @current = current.clone current.bump(type, prerelease_name) SCM. << current current end |
.current ⇒ Object
33 34 35 |
# File 'lib/builderator/control/version.rb', line 33 def current @current ||= SCM..last end |
.from_string(arg, options = {}) ⇒ Object
Parse a SemVer string into a Version
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/builderator/control/version.rb', line 59 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
37 38 39 40 |
# File 'lib/builderator/control/version.rb', line 37 def set_config_version Config.defaults.version = current.to_s Config.recompile end |
.write ⇒ Object
42 43 44 |
# File 'lib/builderator/control/version.rb', line 42 def write current.write end |
Instance Method Details
#prerelease(name = nil) ⇒ Object
Create or bump a new prerelease train
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/builderator/control/version.rb', line 99 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
120 121 122 123 124 125 |
# File 'lib/builderator/control/version.rb', line 120 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
116 117 118 |
# File 'lib/builderator/control/version.rb', line 116 def write Util.relative_path('VERSION').write(to_s) end |