Class: Builderator::Control::Version

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Comparable

#<=>

Methods included from Bump

#bump

Methods included from Auto

#auto_type

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, **options)
  @major = major.to_i
  @minor = minor.to_i
  @patch = patch.to_i
  @build = build.to_i unless build.nil?

  @ref = options[:ref]
end

Instance Attribute Details

#buildObject

Returns the value of attribute build.



96
97
98
# File 'lib/builderator/control/version.rb', line 96

def build
  @build
end

#is_prereleaseObject

Returns the value of attribute is_prerelease.



92
93
94
# File 'lib/builderator/control/version.rb', line 92

def is_prerelease
  @is_prerelease
end

#majorObject

Returns the value of attribute major.



88
89
90
# File 'lib/builderator/control/version.rb', line 88

def major
  @major
end

#minorObject

Returns the value of attribute minor.



89
90
91
# File 'lib/builderator/control/version.rb', line 89

def minor
  @minor
end

#patchObject

Returns the value of attribute patch.



90
91
92
# File 'lib/builderator/control/version.rb', line 90

def patch
  @patch
end

#prerelease_iterationObject

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_nameObject

Returns the value of attribute prerelease_name.



93
94
95
# File 'lib/builderator/control/version.rb', line 93

def prerelease_name
  @prerelease_name
end

#refObject

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.tags << current

  current
end

.currentObject



33
34
35
# File 'lib/builderator/control/version.rb', line 33

def current
  @current ||= SCM.tags.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, options = {})
  matchdata = arg.match(FORMAT)
  return nil if matchdata.nil?

  new(matchdata[:major], matchdata[:minor], matchdata[:patch], matchdata[:build], options).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_versionObject



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

.writeObject



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_sObject



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

#writeObject



116
117
118
# File 'lib/builderator/control/version.rb', line 116

def write
  Util.relative_path('VERSION').write(to_s)
end