Class: Textus::Envelope::IO::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/envelope/io/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

Constructor Details

#initialize(file_store:, manifest:) ⇒ Reader

Returns a new instance of Reader.



15
16
17
18
# File 'lib/textus/envelope/io/reader.rb', line 15

def initialize(file_store:, manifest:)
  @file_store = file_store
  @manifest   = manifest
end

Class Method Details

.from(container:) ⇒ Object



11
12
13
# File 'lib/textus/envelope/io/reader.rb', line 11

def self.from(container:)
  new(file_store: container.file_store, manifest: container.manifest)
end

Instance Method Details

#existing_uid(key) ⇒ Object



35
36
37
38
39
40
# File 'lib/textus/envelope/io/reader.rb', line 35

def existing_uid(key)
  env = read(key)
  env&.uid
rescue StandardError
  nil
end

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/textus/envelope/io/reader.rb', line 42

def exists?(key)
  @file_store.exists?(@manifest.resolver.resolve(key).path)
end

#read(key) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/textus/envelope/io/reader.rb', line 20

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