Class: BigStash::StashOperator
- Inherits:
-
Object
- Object
- BigStash::StashOperator
- Defined in:
- lib/big_stash/stash_operator.rb
Overview
git stash enhancement operator
Instance Attribute Summary collapse
-
#stashes ⇒ Object
readonly
Returns the value of attribute stashes.
Instance Method Summary collapse
- #apply_stash(name) ⇒ Object
-
#initialize(path) ⇒ StashOperator
constructor
A new instance of StashOperator.
- #pop_stash(name) ⇒ Object
- #stash(name) ⇒ Object
- #stash_for_name(name) ⇒ Object
Constructor Details
#initialize(path) ⇒ StashOperator
Returns a new instance of StashOperator.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/big_stash/stash_operator.rb', line 7 def initialize(path) @stashes = {} @path = path IO.popen("cd #{@path}; git stash list") do |io| io.each do |line| items = line.chop.split(/: /) @stashes[items.last] = items.first end end end |
Instance Attribute Details
#stashes ⇒ Object (readonly)
Returns the value of attribute stashes.
5 6 7 |
# File 'lib/big_stash/stash_operator.rb', line 5 def stashes @stashes end |
Instance Method Details
#apply_stash(name) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/big_stash/stash_operator.rb', line 41 def apply_stash(name) if @stashes[name] p `cd #{@path}; git stash apply #{@stashes[name]}` else p %(Nothing to apply, can not find the stash with name '#{name}', continue...) end end |
#pop_stash(name) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/big_stash/stash_operator.rb', line 49 def pop_stash(name) if @stashes[name] p `cd #{@path}; git stash pop #{@stashes[name]}` else p %(Nothing to pop, can not find the stash with name '#{name}', continue...) end end |
#stash(name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/big_stash/stash_operator.rb', line 18 def stash(name) if @stashes[name] raise "Already have a stash with name #{name}" else if can_stash p `cd #{@path}; git stash save #{name}` else p 'Nothing to stash, working tree clean, continue...' end end end |
#stash_for_name(name) ⇒ Object
57 58 59 |
# File 'lib/big_stash/stash_operator.rb', line 57 def stash_for_name(name) @stashes[name] end |