Class: GitBumper::BuildTag

Inherits:
Object
  • Object
show all
Defined in:
lib/git_bumper/build_tag.rb

Overview

This object represents a git build tag. It expects the following format of tags:

PREFIX.BUILD_NUMBER

It provides some methods to parse and increment build numbers.

Constant Summary collapse

REGEX =
/\A([a-z]+)([0-9]+)\z/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, build) ⇒ BuildTag

Returns a new instance of BuildTag.

Parameters:



26
27
28
29
# File 'lib/git_bumper/build_tag.rb', line 26

def initialize(prefix, build)
  @prefix = prefix
  @build = build
end

Instance Attribute Details

#buildObject

Returns the value of attribute build.



22
23
24
# File 'lib/git_bumper/build_tag.rb', line 22

def build
  @build
end

#prefixObject (readonly)

Returns the value of attribute prefix.



21
22
23
# File 'lib/git_bumper/build_tag.rb', line 21

def prefix
  @prefix
end

Class Method Details

.parse(str) ⇒ BuildTag

Parses a string into a BuildTag object.

Parameters:

Returns:

  • or false if str has an invalid format



13
14
15
16
17
18
19
# File 'lib/git_bumper/build_tag.rb', line 13

def self.parse(str)
  matches = str.scan(REGEX).flatten

  return false if matches.empty?

  new(matches[0], matches[1].to_i)
end

Instance Method Details

#incrementObject

Increments the build number.



37
38
39
# File 'lib/git_bumper/build_tag.rb', line 37

def increment(*)
  @build += 1
end

#to_sString

Returns:



32
33
34
# File 'lib/git_bumper/build_tag.rb', line 32

def to_s
  "#{prefix}#{build}"
end