class GitVersionBumper::VersionBumper::Tag

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

Attributes

major[R]
minor[R]
patch[R]

Public Class Methods

current(git_object) click to toggle source
# 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) click to toggle source
# 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
new(major, minor, patch) click to toggle source
# 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

Public Instance Methods

<=>(other) click to toggle source
# 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_s() click to toggle source
# File lib/git_version_bumper/version_bumper/tag.rb, line 33
def to_s
  "v#{major}.#{minor}.#{patch}"
end