Class: SnapshotUI::Snapshot::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/snapshot_ui/snapshot/storage.rb

Class Method Summary collapse

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_directoryObject



11
12
13
# File 'lib/snapshot_ui/snapshot/storage.rb', line 11

def in_progress_directory
  SnapshotUI.configuration.storage_directory.join("in_progress")
end

.listObject



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_progressObject



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_directoryObject



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