Class: Textus::Envelope::Reader
- Inherits:
-
Object
- Object
- Textus::Envelope::Reader
- Defined in:
- lib/textus/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.
Class Method Summary collapse
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.
14 15 16 17 |
# File 'lib/textus/envelope/reader.rb', line 14 def initialize(file_store:, manifest:) @file_store = file_store @manifest = manifest end |
Class Method Details
.from(container:) ⇒ Object
10 11 12 |
# File 'lib/textus/envelope/reader.rb', line 10 def self.from(container:) new(file_store: container.file_store, manifest: container.manifest) end |
Instance Method Details
#existing_uid(key) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/textus/envelope/reader.rb', line 34 def existing_uid(key) env = read(key) env&.uid rescue StandardError nil end |
#exists?(key) ⇒ Boolean
41 42 43 |
# File 'lib/textus/envelope/reader.rb', line 41 def exists?(key) @file_store.exists?(@manifest.resolver.resolve(key).path) end |
#read(key) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/textus/envelope/reader.rb', line 19 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 = Format.for(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 |