Module: Brute::Store::SnapshotStore
- Defined in:
- lib/brute/store/snapshot_store.rb
Overview
Per-path stack of file snapshots used by fs_write, fs_patch, fs_remove to enable undo. Each call to .save pushes the current content (or :did_not_exist for new files). .pop retrieves the most recent snapshot.
Class Method Summary collapse
-
.clear! ⇒ Object
Clear all snapshots.
-
.pop(path) ⇒ Object
Pop and return the most recent snapshot for
path, ornilif there is no history. -
.save(path) ⇒ Object
Push the current content of
pathonto the snapshot stack.
Class Method Details
.clear! ⇒ Object
Clear all snapshots. Used in tests and session resets.
29 30 31 |
# File 'lib/brute/store/snapshot_store.rb', line 29 def clear! @mutex.synchronize { @snapshots.clear } end |
.pop(path) ⇒ Object
Pop and return the most recent snapshot for path, or nil if there is no history.
23 24 25 26 |
# File 'lib/brute/store/snapshot_store.rb', line 23 def pop(path) key = File.(path) @mutex.synchronize { @snapshots[key].pop } end |
.save(path) ⇒ Object
Push the current content of path onto the snapshot stack. If the file doesn’t exist yet, records :did_not_exist.
15 16 17 18 19 |
# File 'lib/brute/store/snapshot_store.rb', line 15 def save(path) key = File.(path) content = File.exist?(key) ? File.read(key) : :did_not_exist @mutex.synchronize { @snapshots[key].push(content) } end |