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



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

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

#get(key) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/textus/store/reader.rb', line 9

def get(key)
  mentry, path, = @manifest.resolve(key)
  raise UnknownKey.new(key, suggestions: @manifest.suggestions_for(key)) unless File.exist?(path)

  raw = File.binread(path)
  parsed = Entry.for_format(mentry.format).parse(raw, path: path)
  meta = parsed["_meta"]
  content = parsed["content"]
  @store.writer.enforce_name_match!(path, meta, mentry.format)
  schema = @store.schema_for(mentry.schema)
  Entry.for_format(mentry.format).validate_against(schema, parsed) if schema
  Envelope.build(
    key: key, mentry: mentry, path: path,
    meta: meta, body: parsed["body"],
    etag: Etag.for_bytes(raw), content: content
  )
end

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



27
28
29
30
31
# File 'lib/textus/store/reader.rb', line 27

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



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

def published   = Dependencies.published_of(@manifest)

#rdeps(key) ⇒ Object



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

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

#schema_envelope(key) ⇒ Object



38
39
40
41
42
# File 'lib/textus/store/reader.rb', line 38

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



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

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.



46
47
48
# File 'lib/textus/store/reader.rb', line 46

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

#validate_allObject



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

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



33
34
35
36
# File 'lib/textus/store/reader.rb', line 33

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