Class: Git::Branches

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/git/branches.rb

Overview

object that holds all the available branches

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Branches

Returns a new instance of Branches.



7
8
9
10
11
12
13
14
15
# File 'lib/git/branches.rb', line 7

def initialize(base)
  @branches = {}
  
  @base = base
        
  @base.lib.branches_all.each do |b|
    @branches[b[0]] = Git::Branch.new(@base, b[0])
  end
end

Instance Method Details

#[](symbol) ⇒ Object



35
36
37
# File 'lib/git/branches.rb', line 35

def [](symbol)
  @branches[symbol.to_s]
end

#each(&block) ⇒ Object



31
32
33
# File 'lib/git/branches.rb', line 31

def each(&block)
  @branches.values.each(&block)
end

#localObject



17
18
19
# File 'lib/git/branches.rb', line 17

def local
  self.select { |b| !b.remote }
end

#remoteObject



21
22
23
# File 'lib/git/branches.rb', line 21

def remote
  self.select { |b| b.remote }
end

#sizeObject

array like methods



27
28
29
# File 'lib/git/branches.rb', line 27

def size
  @branches.size
end

#to_sObject



39
40
41
42
43
44
45
# File 'lib/git/branches.rb', line 39

def to_s
  out = ''
  @branches.each do |k, b|
    out << (b.current ? '* ' : '  ') << b.to_s << "\n"
  end
  out
end