Class: ElocalCapistrano::GitTools::ReleaseTag
- Inherits:
-
Object
- Object
- ElocalCapistrano::GitTools::ReleaseTag
- 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
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#other ⇒ Object
Returns the value of attribute other.
-
#patch ⇒ Object
Returns the value of attribute patch.
Class Method Summary collapse
-
.current(environment = "production") ⇒ Object
Return the current ReleaseTag as specified in versions.yml.
-
.latest ⇒ Object
Return the latest ReleaseTag as computed by looking at the most recent “rel_*” tag created on Git.
Instance Method Summary collapse
-
#<=>(rel_tag) ⇒ Object
Compare two tags by version.
- #==(rel_tag) ⇒ Object
-
#initialize(tag = nil) ⇒ ReleaseTag
constructor
Create a new ReleaseTag from a version string.
-
#to_a ⇒ Object
Version number as an array of integers.
-
#to_s ⇒ Object
Version number as a string, or tag name.
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
#major ⇒ Object
Returns the value of attribute major.
10 11 12 |
# File 'lib/elocal_capistrano/git_tools.rb', line 10 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
10 11 12 |
# File 'lib/elocal_capistrano/git_tools.rb', line 10 def minor @minor end |
#other ⇒ Object
Returns the value of attribute other.
10 11 12 |
# File 'lib/elocal_capistrano/git_tools.rb', line 10 def other @other end |
#patch ⇒ Object
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 |
.latest ⇒ Object
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 = %x(git tag).split("\n").select{|l| l =~ /^rel_/}.map{ |l| ReleaseTag.new(l) }.sort .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_a ⇒ Object
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_s ⇒ Object
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 |