Class: Metanorma::Release::DeltaState
- Inherits:
-
Object
- Object
- Metanorma::Release::DeltaState
- 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.
8 9 10 11 12 |
# File 'lib/metanorma/release/delta_state.rb', line 8 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/metanorma/release/delta_state.rb', line 59 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
27 28 29 |
# File 'lib/metanorma/release/delta_state.rb', line 27 def etag(repo_key) repo_state(repo_key)['etag'] end |
#load ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/metanorma/release/delta_state.rb', line 14 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
51 52 53 54 55 56 57 |
# File 'lib/metanorma/release/delta_state.rb', line 51 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
36 37 38 39 40 41 42 |
# File 'lib/metanorma/release/delta_state.rb', line 36 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
44 45 46 47 48 49 |
# File 'lib/metanorma/release/delta_state.rb', line 44 def release_files(repo_key, tag) releases = repo_state(repo_key)['releases'] return [] unless releases.key?(tag) releases[tag]['files'] || [] end |
#save ⇒ Object
23 24 25 |
# File 'lib/metanorma/release/delta_state.rb', line 23 def save @cache.set('delta_state', JSON.generate(@state)) end |
#set_etag(repo_key, etag_value) ⇒ Object
31 32 33 34 |
# File 'lib/metanorma/release/delta_state.rb', line 31 def set_etag(repo_key, etag_value) repo = ensure_repo(repo_key) repo['etag'] = etag_value end |