Class: SRC::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/src/branch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fromObject (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_toObject (readonly)

Returns the value of attribute merges_to.



6
7
8
# File 'lib/src/branch.rb', line 6

def merges_to
  @merges_to
end

#prefixObject (readonly)

Returns the value of attribute prefix.



6
7
8
# File 'lib/src/branch.rb', line 6

def prefix
  @prefix
end

#semantic_levelObject (readonly)

Returns the value of attribute semantic_level.



6
7
8
# File 'lib/src/branch.rb', line 6

def semantic_level
  @semantic_level
end

#vcObject (readonly)

Returns the value of attribute vc.



6
7
8
# File 'lib/src/branch.rb', line 6

def vc
  @vc
end

Instance Method Details

#cutObject



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

#latestObject



56
57
58
# File 'lib/src/branch.rb', line 56

def latest
  @latest ||= vc.latest(prefix)
end

#mergeObject



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_versionObject



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

Returns:

  • (Boolean)


60
61
62
# File 'lib/src/branch.rb', line 60

def unmerged?
  latest && !latest.subset_of?(merges_to)
end