Class: Git::Stashes

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

Overview

object that holds all the available stashes

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Stashes

Returns a new instance of Stashes.



8
9
10
11
12
13
14
15
16
17
# File 'lib/git/stashes.rb', line 8

def initialize(base)
  @stashes = []

  @base = base

  @base.lib.stashes_all.each do |indexed_message|
    _index, message = indexed_message
    @stashes.unshift(Git::Stash.new(@base, message, save: true))
  end
end

Instance Method Details

#[](index)



52
53
54
# File 'lib/git/stashes.rb', line 52

def [](index)
  @stashes[index.to_i]
end

#allArray

Returns an multi-dimensional Array of elements that have been stash saved. Array is based on position and name. See Example

Examples:

Returns Array of items that have been stashed

.all - [0, "testing-stash-all"]]

Returns:

  • (Array)


26
27
28
# File 'lib/git/stashes.rb', line 26

def all
  @base.lib.stashes_all
end

#apply(index = nil)



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

def apply(index = nil)
  @base.lib.stash_apply(index)
end

#clear



39
40
41
42
# File 'lib/git/stashes.rb', line 39

def clear
  @base.lib.stash_clear
  @stashes = []
end

#each



48
49
50
# File 'lib/git/stashes.rb', line 48

def each(&)
  @stashes.each(&)
end

#save(message)



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

def save(message)
  s = Git::Stash.new(@base, message)
  @stashes.unshift(s) if s.saved?
end

#size



44
45
46
# File 'lib/git/stashes.rb', line 44

def size
  @stashes.size
end