Class: Textus::Application::Envelope::Reader
- Inherits:
-
Object
- Object
- Textus::Application::Envelope::Reader
- Defined in:
- lib/textus/application/envelope/reader.rb
Overview
Read-only counterpart to EnvelopeWriter. Resolves a key, reads the bytes, parses them via the format strategy, and hands back an Envelope. Used by Mv (pre-move inspection) and by EnvelopeWriter (existing-uid lookup for the uid-preservation step in #put).
No audit, no events, no permission checks — those live one layer up.
Instance Method Summary collapse
- #existing_uid(key) ⇒ Object
- #exists?(key) ⇒ Boolean
-
#initialize(file_store:, manifest:) ⇒ Reader
constructor
A new instance of Reader.
- #read(key) ⇒ Object
Constructor Details
#initialize(file_store:, manifest:) ⇒ Reader
Returns a new instance of Reader.
11 12 13 14 |
# File 'lib/textus/application/envelope/reader.rb', line 11 def initialize(file_store:, manifest:) @file_store = file_store @manifest = manifest end |
Instance Method Details
#existing_uid(key) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/textus/application/envelope/reader.rb', line 31 def existing_uid(key) env = read(key) env&.uid rescue StandardError nil end |
#exists?(key) ⇒ Boolean
38 39 40 |
# File 'lib/textus/application/envelope/reader.rb', line 38 def exists?(key) @file_store.exists?(@manifest.resolver.resolve(key).path) end |
#read(key) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/textus/application/envelope/reader.rb', line 16 def read(key) res = @manifest.resolver.resolve(key) path = res.path return nil unless @file_store.exists?(path) mentry = res.entry raw = @file_store.read(path) parsed = Entry.for_format(mentry.format).parse(raw, path: path) Textus::Envelope.build( key: key, mentry: mentry, path: path, meta: parsed["_meta"], body: parsed["body"], etag: Etag.for_bytes(raw), content: parsed["content"] ) end |