summaryrefslogtreecommitdiffstats
path: root/lib/git/stashes.rb
blob: e1287a5fcf9db896055d9ca0c364aaab9773e379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module Git
  
  # object that holds all the available stashes
  class Stashes
    include Enumerable
    
    @base = nil
    @stashes = nil
    
    def initialize(base)
      @stashes = []
      
      @base = base
            
      @base.lib.stashes_all.each do |id, message|
        @stashes.unshift(Git::Stash.new(@base, message, true))
      end
    end
    
    def save(message)
      s = Git::Stash.new(@base, message)
      @stashes.unshift(s) if s.saved?
    end
    
    def apply(index=0)
      @base.lib.stash_apply(index.to_i)
    end
    
    def clear
      @base.lib.stash_clear
      @stashes = []
    end

    def size
      @stashes.size
    end
    
    def each
      @stashes.each do |s|
        yield s
      end
    end
    
    def [](index)
      @stashes[index.to_i]
    end
    
  end
end