Class: SnapshotUI::Snapshot::Storage
- Inherits:
-
Object
- Object
- SnapshotUI::Snapshot::Storage
- Defined in:
- lib/snapshot_ui/snapshot/storage.rb
Class Method Summary collapse
- .clear(directory = nil) ⇒ Object
- .in_progress_directory ⇒ Object
- .list ⇒ Object
- .publish_snapshots_in_progress ⇒ Object
- .read(key) ⇒ Object
- .snapshots_directory ⇒ Object
- .write(key, value) ⇒ Object
Class Method Details
.clear(directory = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/snapshot_ui/snapshot/storage.rb', line 31 def clear(directory = nil) case directory when :snapshots snapshots_directory.rmtree when :in_progress in_progress_directory.rmtree else snapshots_directory.rmtree in_progress_directory.rmtree end end |
.in_progress_directory ⇒ Object
11 12 13 |
# File 'lib/snapshot_ui/snapshot/storage.rb', line 11 def in_progress_directory SnapshotUI.configuration.storage_directory.join("in_progress") end |
.list ⇒ Object
25 26 27 28 29 |
# File 'lib/snapshot_ui/snapshot/storage.rb', line 25 def list Dir .glob("#{snapshots_directory}/**/*.{json}") .map { |file_path| to_key(file_path) } end |
.publish_snapshots_in_progress ⇒ Object
43 44 45 46 |
# File 'lib/snapshot_ui/snapshot/storage.rb', line 43 def publish_snapshots_in_progress clear(:snapshots) in_progress_directory.rename(snapshots_directory) end |
.read(key) ⇒ Object
21 22 23 |
# File 'lib/snapshot_ui/snapshot/storage.rb', line 21 def read(key) to_file_path_for_reading(key).read end |
.snapshots_directory ⇒ Object
7 8 9 |
# File 'lib/snapshot_ui/snapshot/storage.rb', line 7 def snapshots_directory SnapshotUI.configuration.storage_directory.join("snapshots") end |
.write(key, value) ⇒ Object
15 16 17 18 19 |
# File 'lib/snapshot_ui/snapshot/storage.rb', line 15 def write(key, value) file_path = to_file_path_for_writing(key) file_path.dirname.mkpath file_path.write(value) end |