Class: SRC::Branch
- Inherits:
-
Object
- Object
- SRC::Branch
- Defined in:
- lib/src/branch.rb
Instance Attribute Summary collapse
-
#branches_from ⇒ Object
readonly
Returns the value of attribute branches_from.
-
#merges_to ⇒ Object
readonly
Returns the value of attribute merges_to.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#semantic_level ⇒ Object
readonly
Returns the value of attribute semantic_level.
-
#vc ⇒ Object
readonly
Returns the value of attribute vc.
Instance Method Summary collapse
- #cut ⇒ Object
-
#initialize(type) ⇒ Branch
constructor
A new instance of Branch.
- #latest ⇒ Object
- #merge ⇒ Object
- #next_version ⇒ Object
- #unmerged? ⇒ Boolean
Constructor Details
#initialize(type) ⇒ Branch
Returns a new instance of Branch.
8 9 10 11 12 13 14 15 |
# File 'lib/src/branch.rb', line 8 def initialize(type) opts = branches[type.to_sym] || {} @vc = SRC::Git::Branch @branches_from = vc.new(opts[:branches_from]) @prefix = opts[:prefix] @merges_to = vc.new(opts[:merges_to]) @semantic_level = opts[:semantic_level] end |
Instance Attribute Details
#branches_from ⇒ Object (readonly)
Returns the value of attribute branches_from.
6 7 8 |
# File 'lib/src/branch.rb', line 6 def branches_from @branches_from end |
#merges_to ⇒ Object (readonly)
Returns the value of attribute merges_to.
6 7 8 |
# File 'lib/src/branch.rb', line 6 def merges_to @merges_to end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/src/branch.rb', line 6 def prefix @prefix end |
#semantic_level ⇒ Object (readonly)
Returns the value of attribute semantic_level.
6 7 8 |
# File 'lib/src/branch.rb', line 6 def semantic_level @semantic_level end |
#vc ⇒ Object (readonly)
Returns the value of attribute vc.
6 7 8 |
# File 'lib/src/branch.rb', line 6 def vc @vc end |
Instance Method Details
#cut ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/src/branch.rb', line 17 def cut if unmerged? puts "An unmerged #{prefix} branch exists. Checking out." latest.checkout else create_new end end |
#latest ⇒ Object
56 57 58 |
# File 'lib/src/branch.rb', line 56 def latest @latest ||= vc.latest(prefix) end |
#merge ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/src/branch.rb', line 26 def merge if unmerged? if merges_to.subset_of?(latest) merges_to.merge(latest) merges_to.tag else puts "You must first merge #{merges_to} into #{latest}" end else puts "No unmerged #{prefix} branch exists." end end |
#next_version ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/src/branch.rb', line 39 def next_version case semantic_level when 'patch' i = 2 when 'minor' i = 1 when 'major' i = 0 end parts = branches_from.version.split('.') ((i + 1)..2).each { |j| parts[j] = '0' } parts[i] = (parts[i].to_i + 1).to_s parts.join('.') end |
#unmerged? ⇒ Boolean
60 61 62 |
# File 'lib/src/branch.rb', line 60 def unmerged? latest && !latest.subset_of?(merges_to) end |