File: stashes.rb

package info (click to toggle)
ruby-git 1.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,124 kB
  • sloc: ruby: 5,385; sh: 507; perl: 64; makefile: 6
file content (55 lines) | stat: -rw-r--r-- 1,083 bytes parent folder | download | duplicates (2)
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
50
51
52
53
54
55
module Git
  
  # object that holds all the available stashes
  class Stashes
    include Enumerable
    
    def initialize(base)
      @stashes = []
      
      @base = base
            
      @base.lib.stashes_all.each do |id, message|
        @stashes.unshift(Git::Stash.new(@base, message, true))
      end
    end

    #
    # Returns an multi-dimensional Array of elements that have been stash saved.
    # Array is based on position and name. See Example
    #
    # @example Returns Array of items that have been stashed
    #     .all - [0, "testing-stash-all"]]
    # @return [Array]
    def all
      @base.lib.stashes_all
    end
    
    def save(message)
      s = Git::Stash.new(@base, message)
      @stashes.unshift(s) if s.saved?
    end
    
    def apply(index=nil)
      @base.lib.stash_apply(index)
    end
    
    def clear
      @base.lib.stash_clear
      @stashes = []
    end

    def size
      @stashes.size
    end
    
    def each(&block)
      @stashes.each(&block)
    end
    
    def [](index)
      @stashes[index.to_i]
    end
    
  end
end