Class: Hillary::Repo::Version
- Inherits:
-
Object
- Object
- Hillary::Repo::Version
- Defined in:
- lib/hillary/repo/version.rb
Constant Summary collapse
- BRANCHES =
[ DEV = ENV['DEV_BRANCH'] || 'dev', MASTER = ENV['MASTER_BRANCH'] || 'master' ]
- InvalidRepositoryState =
Class.new(StandardError)
Class Method Summary collapse
Instance Method Summary collapse
- #branch ⇒ Object
- #dev? ⇒ Boolean
-
#initialize(repo, options = {}) ⇒ Version
constructor
A new instance of Version.
- #master? ⇒ Boolean
- #name ⇒ Object
- #production? ⇒ Boolean
- #production_tag ⇒ Object (also: #production_tag?)
- #rc_tag ⇒ Object (also: #rc_tag?)
- #sha ⇒ Object
- #sluggable? ⇒ Boolean
- #tag ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(repo, options = {}) ⇒ Version
Returns a new instance of Version.
33 34 35 36 |
# File 'lib/hillary/repo/version.rb', line 33 def initialize(repo, = {}) @repo = repo @options = end |
Class Method Details
.create!(repo = Repo.new('.'), options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hillary/repo/version.rb', line 14 def create!(repo = Repo.new('.'), = {}) = {production: ENV['PRODUCTION']}.merge() version = new(repo, ) if version.master? if version.production? repo.create_production_tag else repo.create_rc_tag end version.validate! end version end |
Instance Method Details
#branch ⇒ Object
42 43 44 |
# File 'lib/hillary/repo/version.rb', line 42 def branch @branch ||= @repo.head.name end |
#dev? ⇒ Boolean
78 79 80 |
# File 'lib/hillary/repo/version.rb', line 78 def dev? branch == DEV end |
#master? ⇒ Boolean
74 75 76 |
# File 'lib/hillary/repo/version.rb', line 74 def master? branch == MASTER end |
#name ⇒ Object
38 39 40 |
# File 'lib/hillary/repo/version.rb', line 38 def name master? ? tag : sha end |
#production? ⇒ Boolean
82 83 84 |
# File 'lib/hillary/repo/version.rb', line 82 def production? @options[:production] end |
#production_tag ⇒ Object Also known as: production_tag?
62 63 64 65 66 67 |
# File 'lib/hillary/repo/version.rb', line 62 def production_tag @production_tag ||= begin production_tag = @repo.last_production_tag production_tag.name if production_tag && production_tag.commit.sha == @repo.last_rc_tag.commit.sha end end |
#rc_tag ⇒ Object Also known as: rc_tag?
54 55 56 57 58 59 |
# File 'lib/hillary/repo/version.rb', line 54 def rc_tag @rc_tag ||= begin rc_tag = @repo.last_rc_tag rc_tag.name if rc_tag && rc_tag.commit.sha == sha end end |
#sha ⇒ Object
50 51 52 |
# File 'lib/hillary/repo/version.rb', line 50 def sha @sha ||= @repo.head.commit.sha end |
#sluggable? ⇒ Boolean
70 71 72 |
# File 'lib/hillary/repo/version.rb', line 70 def sluggable? BRANCHES.include?(branch) end |
#tag ⇒ Object
46 47 48 |
# File 'lib/hillary/repo/version.rb', line 46 def tag @tag ||= production? ? production_tag : rc_tag end |
#validate! ⇒ Object
86 87 88 89 90 91 |
# File 'lib/hillary/repo/version.rb', line 86 def validate! if !@options[:production] && !rc_tag? raise InvalidRepositoryState, "Last RC tag '#{@repo.last_rc_tag.name}' did not point to the current head '#{branch}' (#{sha})" end end |