Class: Textus::Store::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/store/reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Reader

Returns a new instance of Reader.



4
5
6
7
# File 'lib/textus/store/reader.rb', line 4

def initialize(store)
  @store = store
  @manifest = store.manifest
end

Instance Method Details

#deps(key) ⇒ Object



52
# File 'lib/textus/store/reader.rb', line 52

def deps(key)   = Dependencies.deps_of(@manifest, key)

#get(key) ⇒ Object



9
10
11
# File 'lib/textus/store/reader.rb', line 9

def get(key)
  read_raw_envelope(key) || raise(UnknownKey.new(key, suggestions: @manifest.suggestions_for(key)))
end

#list(prefix: nil, zone: nil) ⇒ Object



29
30
31
32
33
# File 'lib/textus/store/reader.rb', line 29

def list(prefix: nil, zone: nil)
  rows = @manifest.enumerate(prefix: prefix)
  rows = rows.select { |r| r[:manifest_entry].zone == zone } if zone
  rows.map { |row| { "key" => row[:key], "zone" => row[:manifest_entry].zone, "path" => row[:path] } }
end

#publishedObject



54
# File 'lib/textus/store/reader.rb', line 54

def published   = Dependencies.published_of(@manifest)

#rdeps(key) ⇒ Object



53
# File 'lib/textus/store/reader.rb', line 53

def rdeps(key)  = Dependencies.rdeps_of(@manifest, key)

#read_raw_envelope(key) ⇒ Object

Reads the current on-disk state of key as a bare envelope, skipping freshness annotation to avoid recursion. Used by Freshness.refresh_sync after a sync refresh completes.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/textus/store/reader.rb', line 16

def read_raw_envelope(key)
  mentry, path, = @manifest.resolve(key)
  return nil unless File.exist?(path)

  raw = File.binread(path)
  parsed = Entry.for_format(mentry.format).parse(raw, path: path)
  Envelope.build(
    key: key, mentry: mentry, path: path,
    meta: parsed["_meta"], body: parsed["body"],
    etag: Etag.for_bytes(raw), content: parsed["content"]
  )
end

#schema_envelope(key) ⇒ Object



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

def schema_envelope(key)
  mentry, = @manifest.resolve(key)
  schema = @store.schema_for(mentry.schema)
  { "protocol" => PROTOCOL, "key" => key, "schema_ref" => mentry.schema, "schema" => schema&.to_h }
end

#stale(prefix: nil, zone: nil) ⇒ Object



56
57
58
# File 'lib/textus/store/reader.rb', line 56

def stale(prefix: nil, zone: nil)
  Staleness.new(manifest: @manifest).call(prefix: prefix, zone: zone)
end

#uid(key) ⇒ Object

Returns the Textus UID for a key (or nil if the entry has none yet). Raises UnknownKey if the key doesn’t resolve to a real file.



48
49
50
# File 'lib/textus/store/reader.rb', line 48

def uid(key)
  get(key)["uid"]
end

#validate_allObject



60
61
62
63
64
65
66
# File 'lib/textus/store/reader.rb', line 60

def validate_all
  Validator.new(
    reader: self, manifest: @manifest,
    audit_log: @store.audit_log,
    schema_for: ->(name) { @store.schema_for(name) }
  ).call
end

#where(key) ⇒ Object



35
36
37
38
# File 'lib/textus/store/reader.rb', line 35

def where(key)
  mentry, path, = @manifest.resolve(key)
  { "protocol" => PROTOCOL, "key" => key, "zone" => mentry.zone, "owner" => mentry.owner, "path" => path }
end