Class: GitVersionBumper::VersionBumper::Tag

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/git_version_bumper/version_bumper/tag.rb

Overview

Local represenation of Git::Object::Tag Created to allow for custom sorting of git tags

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, patch) ⇒ Tag

Returns a new instance of Tag.



10
11
12
13
14
# File 'lib/git_version_bumper/version_bumper/tag.rb', line 10

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

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



8
9
10
# File 'lib/git_version_bumper/version_bumper/tag.rb', line 8

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



8
9
10
# File 'lib/git_version_bumper/version_bumper/tag.rb', line 8

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



8
9
10
# File 'lib/git_version_bumper/version_bumper/tag.rb', line 8

def patch
  @patch
end

Class Method Details

.current(git_object) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/git_version_bumper/version_bumper/tag.rb', line 16

def self.current(git_object)
  tags = git_object.tags
  return Tag.new(0, 0, 0) if tags.empty?

  tags
    .map { |tag| Tag.from_name(tag.name) }
    .sort
    .last
end

.from_name(tag_name) ⇒ Object



26
27
28
29
30
31
# File 'lib/git_version_bumper/version_bumper/tag.rb', line 26

def self.from_name(tag_name)
  tag_name = tag_name.sub('v', '')
  major, minor, patch = tag_name.split('.')

  Tag.new(major, minor, patch)
end

Instance Method Details

#<=>(other) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/git_version_bumper/version_bumper/tag.rb', line 37

def <=>(other)
  if major == other.major
    if minor == other.minor
      patch <=> other.patch
    else
      minor <=> other.minor
    end
  else
    major <=> other.major
  end
end

#to_sObject



33
34
35
# File 'lib/git_version_bumper/version_bumper/tag.rb', line 33

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