Class: GitBumper::Tag

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

Overview

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

PREFIX.MAJOR.MINOR.PATCH

It provides some methods to parse and increment version numbers.

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, major, minor, patch) ⇒ Tag

Returns a new instance of Tag.

Parameters:

  • prefix (String)
  • major (Fixnum)
  • minor (Fixnum)
  • patch (Fixnum)


30
31
32
33
34
35
# File 'lib/git_bumper/tag.rb', line 30

def initialize(prefix, major, minor, patch)
  @prefix = prefix
  @major = major
  @minor = minor
  @patch = patch
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



24
25
26
# File 'lib/git_bumper/tag.rb', line 24

def major
  @major
end

#minorObject

Returns the value of attribute minor.



24
25
26
# File 'lib/git_bumper/tag.rb', line 24

def minor
  @minor
end

#patchObject

Returns the value of attribute patch.



24
25
26
# File 'lib/git_bumper/tag.rb', line 24

def patch
  @patch
end

#prefixObject (readonly)

Returns the value of attribute prefix.



23
24
25
# File 'lib/git_bumper/tag.rb', line 23

def prefix
  @prefix
end

Class Method Details

.parse(str) ⇒ Tag

Parses a string into a Tag object.

Parameters:

  • str (String)

Returns:

  • (Tag)

    or false if str has an invalid format



12
13
14
15
16
17
18
19
20
21
# File 'lib/git_bumper/tag.rb', line 12

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

  return false if matches.empty?

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

Instance Method Details

#increment(part) ⇒ Object

Increments a part of the version.



43
44
45
46
47
48
49
50
51
52
# File 'lib/git_bumper/tag.rb', line 43

def increment(part)
  case part
  when :major
    @major += 1
  when :minor
    @minor += 1
  when :patch
    @patch += 1
  end
end

#to_sString

Returns:

  • (String)


38
39
40
# File 'lib/git_bumper/tag.rb', line 38

def to_s
  "#{prefix}#{major}.#{minor}.#{patch}"
end