Class: Git::Managed::Branch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBranch

Returns a new instance of Branch.



4
5
6
7
# File 'lib/managed/branch.rb', line 4

def initialize
  @branches = `git branch`.split /\n/
  partition_branches
end

Instance Attribute Details

#branchesObject

Returns the value of attribute branches.



2
3
4
# File 'lib/managed/branch.rb', line 2

def branches
  @branches
end

#branches_to_deleteObject

Returns the value of attribute branches_to_delete.



2
3
4
# File 'lib/managed/branch.rb', line 2

def branches_to_delete
  @branches_to_delete
end

#current_branchObject

Returns the value of attribute current_branch.



2
3
4
# File 'lib/managed/branch.rb', line 2

def current_branch
  @current_branch
end

Instance Method Details

#delete_branch(branch) ⇒ Object



23
24
25
# File 'lib/managed/branch.rb', line 23

def delete_branch branch
  `git branch -D #{branch}`
end

#delete_branchesObject



16
17
18
19
20
21
# File 'lib/managed/branch.rb', line 16

def delete_branches
  return false if @branches_to_delete.length == 0
  @branches_to_delete.each do |branch|
    delete_branch( branch.gsub /\s/, '' )
  end
end

#partition_branchesObject



9
10
11
12
13
14
# File 'lib/managed/branch.rb', line 9

def partition_branches
  @current_branch = @branches.select {|branch| branch.match /^\*/}.first
  @branches_to_delete = @branches.select {|branch| branch != @current_branch }
  @current_branch.chomp!
  @current_branch.gsub! /\s|\*/, ''
end