Class: Textus::Store::Entry::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/store/entry/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-meta lookup for the uid/sources 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:, layout:) ⇒ Reader

Returns a new instance of Reader.



20
21
22
23
24
# File 'lib/textus/store/entry/reader.rb', line 20

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

Class Method Details

.from(container:) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/textus/store/entry/reader.rb', line 11

def self.from(container:)
  # Prefer a cached reader on the container (injection point) for
  # tests and alternative runtimes. Fall back to constructing one.
  return container.reader if container.respond_to?(:reader) && container.reader

  new(file_store: container.file_store, manifest: container.manifest,
      layout: container.layout)
end

Instance Method Details

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/textus/store/entry/reader.rb', line 41

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

#read(key) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/textus/store/entry/reader.rb', line 26

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::Value::Envelope.build(
    key: key, mentry: mentry, path: path,
    meta: parsed["_meta"], body: parsed["body"],
    etag: Value::Etag.for_bytes(raw), content: parsed["content"]
  )
end