Sha256: 8e3886da3f35855c57c7179b6526d8a649c8919819915cd775eab114b51fc03e

Contents?: true

Size: 919 Bytes

Versions: 4

Compression:

Stored size: 919 Bytes

Contents

module Git
  
  # object that holds all the available branches
  class Branches
    include Enumerable
    
    @base = nil
    @branches = nil
    
    def initialize(base)
      @branches = {}
      
      @base = base
            
      @base.lib.branches_all.each do |b|
        @branches[b[0]] = Git::Branch.new(@base, b[0])
      end
    end

    def local
      self.select { |b| !b.remote }
    end
    
    def remote
      self.select { |b| b.remote }
    end
    
    # array like methods

    def size
      @branches.size
    end    
    
    def each
      @branches.each do |k, b|
        yield b
      end
    end
    
    def [](symbol)
      @branches[symbol.to_s]
    end
    
    def to_s
      out = ''
      @branches.each do |k, b|
        if b.current
          out += "* " + b.to_s + "\n"
        else
          out += "  " + b.to_s + "\n"
        end
      end
      out
    end
    
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
iownbey-git-1.0.7.1 lib/git/branches.rb
schacon-git-1.0.6 lib/git/branches.rb
schacon-git-1.0.7 lib/git/branches.rb
git-1.0.5 lib/git/branches.rb