Class: Textus::Store::Staleness::GeneratorCheck

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

Overview

Reports staleness for generator-zone entries — derived files whose generator’s listed sources have been modified more recently than the entry’s ‘_meta.generated.at` timestamp. Returns an Array of row hashes (possibly empty) per entry.

Instance Method Summary collapse

Constructor Details

#initialize(manifest:) ⇒ GeneratorCheck

Returns a new instance of GeneratorCheck.



11
12
13
# File 'lib/textus/store/staleness/generator_check.rb', line 11

def initialize(manifest:)
  @manifest = manifest
end

Instance Method Details

#rows_for(mentry) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/textus/store/staleness/generator_check.rb', line 15

def rows_for(mentry)
  return [] unless mentry.in_generator_zone?

  gen = mentry.generator
  return [] unless gen

  path = Textus::Key::Path.resolve(@manifest, mentry)
  return [stale_row(mentry, path, "derived entry has never been generated")] unless File.exist?(path)

  parsed = Entry.for_format(mentry.format).parse(File.binread(path), path: path)
  generated_at = parsed["_meta"].dig("generated", "at")
  return [stale_row(mentry, path, "missing generated.at frontmatter")] unless generated_at

  gen_time = parse_time(generated_at)
  return [stale_row(mentry, path, "unparseable generated.at: #{generated_at.inspect}")] unless gen_time

  offender = newest_source_after(gen, gen_time)
  return [stale_row(mentry, path, "source '#{offender}' modified after generated.at")] if offender

  []
end