added branch and checkout functionality
[rubygit.git] / lib / git / branches.rb
blob47d001a0f6d3821f36361205d6a2b378a3747828
1 module Git
2   
3   # object that holds all the available branches
4   class Branches
5     include Enumerable
6     
7     @base = nil
8     @branches = nil
9     
10     def initialize(base)
11       @branches = {}
12       
13       @base = base
14             
15       @base.lib.branches_all.each do |b|
16         @branches[b[0]] = Git::Branch.new(@base, b[0])
17       end
18     end
20     def local
21       self.select { |b| !b.remote }
22     end
23     
24     def remote
25       self.select { |b| b.remote }
26     end
27     
28     # array like methods
30     def size
31       @branches.size
32     end    
33     
34     def each
35       @branches.each do |k, b|
36         yield b
37       end
38     end
39     
40     def [](symbol)
41       @branches[symbol.to_s]
42     end
43     
44   end
45 end