Class: Textus::Port::Storage::FileStore
- Inherits:
-
Object
- Object
- Textus::Port::Storage::FileStore
- Includes:
- Interface
- Defined in:
- lib/textus/port/storage/file_store.rb
Overview
Pure filesystem I/O port. Wraps File/FileUtils/Etag with no knowledge of envelopes, entries, schemas, or audit.
Instance Method Summary collapse
-
#delete(path) ⇒ Object
Raises Errno::ENOENT if absent — mirrors File.delete and matches the semantics used by Store::Writer (which guards with File.exist? first).
- #dir_empty?(dir) ⇒ Boolean
- #etag(path) ⇒ Object
- #exists?(path) ⇒ Boolean
-
#mkdir_p(path) ⇒ Object
Convenience filesystem ops so callers can go through the port instead of calling FileUtils/Dir directly.
- #mv(from_path, to_path) ⇒ Object
- #read(path) ⇒ Object
- #rmdir(path) ⇒ Object
- #write(path, bytes) ⇒ Object
Instance Method Details
#delete(path) ⇒ Object
Raises Errno::ENOENT if absent — mirrors File.delete and matches the semantics used by Store::Writer (which guards with File.exist? first).
20 |
# File 'lib/textus/port/storage/file_store.rb', line 20 def delete(path) = File.delete(path) |
#dir_empty?(dir) ⇒ Boolean
42 43 44 45 |
# File 'lib/textus/port/storage/file_store.rb', line 42 def dir_empty?(dir) # Dir.empty? exists on modern Rubies; wrap for clarity Dir.empty?(dir) end |
#etag(path) ⇒ Object
24 |
# File 'lib/textus/port/storage/file_store.rb', line 24 def etag(path) = Value::Etag.for_file(path) |
#exists?(path) ⇒ Boolean
22 |
# File 'lib/textus/port/storage/file_store.rb', line 22 def exists?(path) = File.exist?(path) |
#mkdir_p(path) ⇒ Object
Convenience filesystem ops so callers can go through the port instead of calling FileUtils/Dir directly. Keeps filesystem semantics in one place for easier testing and replacement.
29 30 31 |
# File 'lib/textus/port/storage/file_store.rb', line 29 def mkdir_p(path) FileUtils.mkdir_p(path) end |
#mv(from_path, to_path) ⇒ Object
33 34 35 36 |
# File 'lib/textus/port/storage/file_store.rb', line 33 def mv(from_path, to_path) FileUtils.mkdir_p(File.dirname(to_path)) FileUtils.mv(from_path, to_path) end |
#read(path) ⇒ Object
11 |
# File 'lib/textus/port/storage/file_store.rb', line 11 def read(path) = File.binread(path) |
#rmdir(path) ⇒ Object
38 39 40 |
# File 'lib/textus/port/storage/file_store.rb', line 38 def rmdir(path) Dir.rmdir(path) end |
#write(path, bytes) ⇒ Object
13 14 15 16 |
# File 'lib/textus/port/storage/file_store.rb', line 13 def write(path, bytes) FileUtils.mkdir_p(File.dirname(path)) File.binwrite(path, bytes) end |