Module: Brute::Tools::FS::SnapshotStore
- Defined in:
- lib/brute/tools/fs/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.
34 35 36 |
# File 'lib/brute/tools/fs/snapshot_store.rb', line 34 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.
28 29 30 31 |
# File 'lib/brute/tools/fs/snapshot_store.rb', line 28 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.
20 21 22 23 24 |
# File 'lib/brute/tools/fs/snapshot_store.rb', line 20 def save(path) key = File.(path) content = File.exist?(key) ? File.read(key) : :did_not_exist @mutex.synchronize { @snapshots[key].push(content) } end |