Class: SnapshotInspector::Storage
- Inherits:
-
Object
- Object
- SnapshotInspector::Storage
- Defined in:
- lib/snapshot_inspector/storage.rb
Class Method Summary collapse
- .clear(directory = nil) ⇒ Object
- .list ⇒ Object
- .move_files_from_processing_directory_to_snapshots_directory ⇒ Object
- .processing_directory ⇒ Object
- .read(key) ⇒ Object
- .snapshots_directory ⇒ Object
- .write(key, value) ⇒ Object
Class Method Details
.clear(directory = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/snapshot_inspector/storage.rb', line 28 def clear(directory = nil) case directory when :snapshots snapshots_directory.rmtree when :processing processing_directory.rmtree else snapshots_directory.rmtree processing_directory.rmtree end end |
.list ⇒ Object
22 23 24 25 26 |
# File 'lib/snapshot_inspector/storage.rb', line 22 def list Dir .glob("#{snapshots_directory}/**/*.{json}") .map { |file_path| to_key(file_path) } end |
.move_files_from_processing_directory_to_snapshots_directory ⇒ Object
40 41 42 43 |
# File 'lib/snapshot_inspector/storage.rb', line 40 def move_files_from_processing_directory_to_snapshots_directory clear(:snapshots) processing_directory.rename(snapshots_directory) end |
.processing_directory ⇒ Object
8 9 10 |
# File 'lib/snapshot_inspector/storage.rb', line 8 def processing_directory SnapshotInspector.configuration.storage_directory.join("processing") end |
.read(key) ⇒ Object
18 19 20 |
# File 'lib/snapshot_inspector/storage.rb', line 18 def read(key) File.read(to_file_path_for_reading(key)) end |
.snapshots_directory ⇒ Object
4 5 6 |
# File 'lib/snapshot_inspector/storage.rb', line 4 def snapshots_directory SnapshotInspector.configuration.storage_directory.join("snapshots") end |
.write(key, value) ⇒ Object
12 13 14 15 16 |
# File 'lib/snapshot_inspector/storage.rb', line 12 def write(key, value) file_path = to_file_path_for_writing(key) file_path.dirname.mkpath file_path.write(value) end |