Class: Upkeep::HerbSupport::ManifestCache

Inherits:
Object
  • Object
show all
Defined in:
lib/upkeep/herb/manifest_cache.rb

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManifestCache

Returns a new instance of ManifestCache.



13
14
15
# File 'lib/upkeep/herb/manifest_cache.rb', line 13

def initialize
  @entries = {}
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



11
12
13
# File 'lib/upkeep/herb/manifest_cache.rb', line 11

def entries
  @entries
end

Instance Method Details

#clearObject



44
45
46
# File 'lib/upkeep/herb/manifest_cache.rb', line 44

def clear
  entries.clear
end

#fetch(path:, source:, parse_options: ManifestDiff::PARSE_OPTIONS) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/upkeep/herb/manifest_cache.rb', line 17

def fetch(path:, source:, parse_options: ManifestDiff::PARSE_OPTIONS)
  source_digest = digest(source)
  entry = entries[path]

  return entry.manifest if entry&.source_digest == source_digest

  update = update_for(path: path, old_source: entry&.source, new_source: source, parse_options: parse_options)
  manifest = update[:new_manifest] || TemplateManifest.build(path: path, source: source, parse_options: parse_options)
  entries[path] = Entry.new(path, source_digest, source.dup, manifest, update_payload(update))

  manifest
end

#last_update_for(path) ⇒ Object



30
31
32
# File 'lib/upkeep/herb/manifest_cache.rb', line 30

def last_update_for(path)
  entries.fetch(path).last_update
end

#summaryObject



34
35
36
37
38
39
40
41
42
# File 'lib/upkeep/herb/manifest_cache.rb', line 34

def summary
  updates = entries.values.map(&:last_update)

  {
    entries: entries.size,
    actions: updates.map { |update| update.fetch(:action) }.tally,
    topology_changes: updates.count { |update| update.fetch(:topology_changed, false) }
  }
end