Class: Memoria::SnapshotSaver
- Inherits:
-
Object
- Object
- Memoria::SnapshotSaver
- Defined in:
- lib/memoria/snapshot_saver.rb
Overview
Reads and writes snapshots to and from the file system.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ SnapshotSaver
constructor
Creates a new SnapshotSaver.
-
#read(file_name) ⇒ String
Retrieves the snapshot contents for the given storage key (file name).
-
#snapshot_exists?(file_name) ⇒ SnapshotSaver
Whether a snapshot for the given storage key (file name) is persisted in the file system.
-
#write(file_name, content) ⇒ Fixnum
Persists the snapshot contents for the given storage key (file name).
Constructor Details
#initialize(configuration) ⇒ SnapshotSaver
Creates a new SnapshotSaver.
17 18 19 |
# File 'lib/memoria/snapshot_saver.rb', line 17 def initialize(configuration) @configuration = configuration end |
Instance Method Details
#read(file_name) ⇒ String
Retrieves the snapshot contents for the given storage key (file name).
55 56 57 58 59 |
# File 'lib/memoria/snapshot_saver.rb', line 55 def read(file_name) path = absolute_path_to_file(file_name) return nil unless File.exist?(path) File.read(path) end |
#snapshot_exists?(file_name) ⇒ SnapshotSaver
Whether a snapshot for the given storage key (file name) is persisted in the file system.
33 34 35 36 37 |
# File 'lib/memoria/snapshot_saver.rb', line 33 def snapshot_exists?(file_name) location = absolute_path_to_file(file_name) return false if location.nil? File.exist?(location) end |
#write(file_name, content) ⇒ Fixnum
Persists the snapshot contents for the given storage key (file name).
76 77 78 79 80 81 |
# File 'lib/memoria/snapshot_saver.rb', line 76 def write(file_name, content) path = absolute_path_to_file(file_name) directory = File.dirname(path) FileUtils.mkdir_p(directory) unless File.exist?(directory) File.binwrite(path, content) end |