Class: Metanorma::Release::DeltaState
- Inherits:
-
Object
- Object
- Metanorma::Release::DeltaState
- Includes:
- DeltaStateManager
- Defined in:
- lib/metanorma/release/delta_state.rb
Instance Method Summary collapse
- #cleanup_stale(repo_key, current_tags) ⇒ Object
- #etag(repo_key) ⇒ Object
-
#initialize(cache_store:, output_dir:) ⇒ DeltaState
constructor
A new instance of DeltaState.
- #load ⇒ Object
- #mark_processed(repo_key, tag, content_hash, files) ⇒ Object
- #processed?(repo_key, tag, content_hash) ⇒ Boolean
- #release_files(repo_key, tag) ⇒ Object
- #save ⇒ Object
- #set_etag(repo_key, etag_value) ⇒ Object
Constructor Details
#initialize(cache_store:, output_dir:) ⇒ DeltaState
Returns a new instance of DeltaState.
45 46 47 48 49 |
# File 'lib/metanorma/release/delta_state.rb', line 45 def initialize(cache_store:, output_dir:) @cache = cache_store @output_dir = output_dir @state = empty_state end |
Instance Method Details
#cleanup_stale(repo_key, current_tags) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/metanorma/release/delta_state.rb', line 96 def cleanup_stale(repo_key, ) repo = repo_state(repo_key) releases = repo["releases"] removed = 0 releases.each do |tag, entry| next if .include?(tag) (entry["files"] || []).each do |file| path = File.join(@output_dir, file) if File.exist?(path) File.delete(path) removed += 1 end end releases.delete(tag) end removed end |
#etag(repo_key) ⇒ Object
64 65 66 |
# File 'lib/metanorma/release/delta_state.rb', line 64 def etag(repo_key) repo_state(repo_key)["etag"] end |
#load ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/metanorma/release/delta_state.rb', line 51 def load raw = @cache.get("delta_state") return if raw.nil? @state = JSON.parse(raw) rescue JSON::ParserError @state = empty_state end |
#mark_processed(repo_key, tag, content_hash, files) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/metanorma/release/delta_state.rb', line 88 def mark_processed(repo_key, tag, content_hash, files) repo = ensure_repo(repo_key) repo["releases"][tag] = { "content_hash" => content_hash.to_s, "files" => files, } end |
#processed?(repo_key, tag, content_hash) ⇒ Boolean
73 74 75 76 77 78 79 |
# File 'lib/metanorma/release/delta_state.rb', line 73 def processed?(repo_key, tag, content_hash) releases = repo_state(repo_key)["releases"] return false unless releases.key?(tag) return false if content_hash.nil? releases[tag]["content_hash"] == content_hash.to_s end |
#release_files(repo_key, tag) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/metanorma/release/delta_state.rb', line 81 def release_files(repo_key, tag) releases = repo_state(repo_key)["releases"] return [] unless releases.key?(tag) releases[tag]["files"] || [] end |
#save ⇒ Object
60 61 62 |
# File 'lib/metanorma/release/delta_state.rb', line 60 def save @cache.set("delta_state", JSON.generate(@state)) end |
#set_etag(repo_key, etag_value) ⇒ Object
68 69 70 71 |
# File 'lib/metanorma/release/delta_state.rb', line 68 def set_etag(repo_key, etag_value) repo = ensure_repo(repo_key) repo["etag"] = etag_value end |