Class: CrossStub::Stores::Base
- Inherits:
-
Object
- Object
- CrossStub::Stores::Base
- Defined in:
- lib/cross-stub/stores/base.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #get(mode = :current) ⇒ Object
-
#initialize(truncate) ⇒ Base
constructor
A new instance of Base.
- #set(data, mode = :current) ⇒ Object
Constructor Details
#initialize(truncate) ⇒ Base
Returns a new instance of Base.
8 9 10 |
# File 'lib/cross-stub/stores/base.rb', line 8 def initialize(truncate) truncate && dump(current, {}) end |
Instance Method Details
#clear ⇒ Object
31 32 33 34 |
# File 'lib/cross-stub/stores/base.rb', line 31 def clear set(get(:current), :previous) unless exists?(previous) delete(current) end |
#get(mode = :current) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cross-stub/stores/base.rb', line 12 def get(mode = :current) case mode when :current then load(current) when :previous data = load(previous) delete(previous) data else raise UnsupportedStoreGetMode end end |
#set(data, mode = :current) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/cross-stub/stores/base.rb', line 23 def set(data, mode = :current) case mode when :current then dump(current, data) when :previous then dump(previous, data) else raise UnsupportedStoreGetMode end end |