class Tagit::Version

Constants

VERSION_REGEX

Attributes

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

Public Class Methods

all() click to toggle source
# File lib/tagit/version.rb, line 24
def self.all
  lines = git_tags.split("\n")
  lines.inject([]) do |results, line|
    results << Version.new($1, $2, $3) if VERSION_REGEX.match(line)
    results
  end
end
current() click to toggle source
# File lib/tagit/version.rb, line 20
def self.current
  all.sort.last
end
from_s(str) click to toggle source
# File lib/tagit/version.rb, line 15
def self.from_s(str)
  raise ArgumentError, "Not a conventional version string - '#{str}'" unless VERSION_REGEX.match(str)
  Version.new($1, $2, $3)
end
new(major, minor, patch = nil) click to toggle source
# File lib/tagit/version.rb, line 10
def initialize(major, minor, patch = nil)
  @major, @minor= major.to_i, minor.to_i
  @patch = patch.to_i if patch
end

Private Class Methods

git_tags() click to toggle source
# File lib/tagit/version.rb, line 52
def self.git_tags
  run('git tag')
end
run(command) click to toggle source
# File lib/tagit/version.rb, line 47
def self.run(command)
  raise RuntimeError, "#{Rails.root} is not a git root" unless File.exists?(File.join(Rails.root, ('.git/HEAD')))
  `cd #{Rails.root} && #{command}`
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/tagit/version.rb, line 32
def <=> other
  return 1 if other.nil?

  [:major, :minor, :patch].each do |sym|
    compare = ((self.send(sym) || 0) <=> (other.send(sym) || 0))
    return compare unless compare == 0 && sym != :patch
  end
end
to_s() click to toggle source
# File lib/tagit/version.rb, line 41
def to_s
  "v#{major}.#{minor}#{".#{patch}" if patch}"
end