Module: AnotherBrick::Tag

Extended by:
Tag
Included in:
Tag
Defined in:
lib/another_brick/tag.rb

Constant Summary collapse

PREFIXES =
%w(unstable stable testing)
TAG_RE =
/^(#{PREFIXES.map {|p| "#{p}"}.join("|") })(?:_(\d+.\d+.\d+))?$/

Instance Method Summary collapse

Instance Method Details

#build_tag(tag) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/another_brick/tag.rb', line 15

def build_tag(tag)
  captures = TAG_RE.match(tag).captures

  if captures[1]
    tag
  else
    major, minor, build = last_tag ? strip_version(last_tag) : [0, 0, 0]

    "#{captures[0]}_#{major}.#{minor}.#{build.to_i + 1}"
  end
end

#create(tag) ⇒ Object



8
9
10
11
12
13
# File 'lib/another_brick/tag.rb', line 8

def create(tag)
  build_tag(tag).tap do |next_tag|
    `git tag #{next_tag}`
    `git push --tags`
  end
end

#last_tagObject



33
34
35
36
37
38
# File 'lib/another_brick/tag.rb', line 33

def last_tag
  prefix_re = /(?:v|#{PREFIXES.map { |e| "#{e}_" }.join("|") })(\d+\.\d+(?:\.\d+)?)/
  `git tag `.lines.map(&:chomp).select { |e| e =~ prefix_re }.map do |line|
    line.gsub(prefix_re, "\\1")
  end.sort(&version_sorter).last
end

#strip_version(version) ⇒ Object



40
41
42
43
44
# File 'lib/another_brick/tag.rb', line 40

def strip_version(version)
  version.split('.').map(&:to_i).tap do |v|
    v[2] ||= -1
  end
end

#version_sorterObject



27
28
29
30
31
# File 'lib/another_brick/tag.rb', line 27

def version_sorter
  proc do |v1, v2|
    Gem::Version.new(v1) <=> Gem::Version.new(v2)
  end
end