Class: GitTools::ReleaseTag
- Inherits:
-
Object
- Object
- GitTools::ReleaseTag
- Defined in:
- lib/rain/git_tools/release_tag.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.
11 12 13 |
# File 'lib/rain/git_tools/release_tag.rb', line 11 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.
8 9 10 |
# File 'lib/rain/git_tools/release_tag.rb', line 8 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
8 9 10 |
# File 'lib/rain/git_tools/release_tag.rb', line 8 def minor @minor end |
#other ⇒ Object
Returns the value of attribute other.
8 9 10 |
# File 'lib/rain/git_tools/release_tag.rb', line 8 def other @other end |
#patch ⇒ Object
Returns the value of attribute patch.
8 9 10 |
# File 'lib/rain/git_tools/release_tag.rb', line 8 def patch @patch end |
Class Method Details
.current(environment = "production") ⇒ Object
Return the current ReleaseTag as specified in versions.yml.
35 36 37 |
# File 'lib/rain/git_tools/release_tag.rb', line 35 def self.current environment="production" ReleaseTag.new(Rain.version[environment]) end |
.latest ⇒ Object
Return the latest ReleaseTag as computed by looking at the most recent “rel_*” tag created on Git.
41 42 43 44 |
# File 'lib/rain/git_tools/release_tag.rb', line 41 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.
21 22 23 |
# File 'lib/rain/git_tools/release_tag.rb', line 21 def <=>(rel_tag) to_a <=> rel_tag.to_a end |
#==(rel_tag) ⇒ Object
30 31 32 |
# File 'lib/rain/git_tools/release_tag.rb', line 30 def ==(rel_tag) to_a == rel_tag.to_a end |
#to_a ⇒ Object
Version number as an array of integers.
16 17 18 |
# File 'lib/rain/git_tools/release_tag.rb', line 16 def to_a [@major, @minor, @patch, @other].compact end |
#to_s ⇒ Object
Version number as a string, or tag name.
26 27 28 |
# File 'lib/rain/git_tools/release_tag.rb', line 26 def to_s "rel_" + to_a.compact.join(".") end |