Class: ElocalCapistrano::GitTools::ReleaseTag

Inherits:
Object
  • Object
show all
Defined in:
lib/elocal_capistrano/git_tools.rb

Overview

Represents an API release, which is tagged in the repository as rel_<MAJOR>.<MINOR>.<PATCH>. Capistrano uses this pushed tag to deploy the next version of the API, which is reflected in the footer of each page. In development mode, this simply returns the latest commit in master.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag = nil) ⇒ ReleaseTag

Create a new ReleaseTag from a version string.



13
14
15
# File 'lib/elocal_capistrano/git_tools.rb', line 13

def initialize(tag=nil)
  @major, @minor, @patch, @other = tag.gsub(/^rel_/,'').split(/[^0-9a-zA-Z]+/).map(&:to_i) unless tag.nil?
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



10
11
12
# File 'lib/elocal_capistrano/git_tools.rb', line 10

def major
  @major
end

#minorObject

Returns the value of attribute minor.



10
11
12
# File 'lib/elocal_capistrano/git_tools.rb', line 10

def minor
  @minor
end

#otherObject

Returns the value of attribute other.



10
11
12
# File 'lib/elocal_capistrano/git_tools.rb', line 10

def other
  @other
end

#patchObject

Returns the value of attribute patch.



10
11
12
# File 'lib/elocal_capistrano/git_tools.rb', line 10

def patch
  @patch
end

Class Method Details

.current(environment = "production") ⇒ Object

Return the current ReleaseTag as specified in versions.yml.



37
38
39
# File 'lib/elocal_capistrano/git_tools.rb', line 37

def self.current(environment="production")
  ReleaseTag.new(versions_hash[environment])
end

.latestObject

Return the latest ReleaseTag as computed by looking at the most recent “rel_*” tag created on Git.



43
44
45
46
# File 'lib/elocal_capistrano/git_tools.rb', line 43

def self.latest
  tags = %x(git tag).split("\n").select{|l| l =~ /^rel_/}.map{ |l| ReleaseTag.new(l) }.sort
  tags.last || ReleaseTag.new('rel_0.0.0')
end

Instance Method Details

#<=>(rel_tag) ⇒ Object

Compare two tags by version. The latest version is always chosen.



23
24
25
# File 'lib/elocal_capistrano/git_tools.rb', line 23

def <=>(rel_tag)
  to_a <=> rel_tag.to_a
end

#==(rel_tag) ⇒ Object



32
33
34
# File 'lib/elocal_capistrano/git_tools.rb', line 32

def ==(rel_tag)
  to_a == rel_tag.to_a
end

#to_aObject

Version number as an array of integers.



18
19
20
# File 'lib/elocal_capistrano/git_tools.rb', line 18

def to_a
  [@major, @minor, @patch, @other].compact
end

#to_sObject

Version number as a string, or tag name.



28
29
30
# File 'lib/elocal_capistrano/git_tools.rb', line 28

def to_s
  "rel_" + to_a.compact.join(".")
end