Class: Ruborg::ArchiveCache
- Inherits:
-
Object
- Object
- Ruborg::ArchiveCache
- Defined in:
- lib/ruborg/archive_cache.rb
Overview
Persistent cache of per-archive metadata, stored as a JSON file sibling to the Borg repository. Eliminates repeated ‘borg info` calls across runs.
Supports local paths (File::LOCK_EX) and SSH paths (optimistic merge via scp). All metadata is stored and returned with symbol keys (:path, :size, :hash, :source_dir).
Constant Summary collapse
- SSH_PATTERN =
%r{\A(?:ssh://|[^\s/]+@[^\s:]+:)}
Instance Method Summary collapse
- #[](archive_name) ⇒ Object
-
#entries ⇒ Object
Returns all cached entries as an array of hashes, each including :archive_name.
- #fetch ⇒ Object
-
#initialize(repo_path) ⇒ ArchiveCache
constructor
A new instance of ArchiveCache.
- #save_if_changed ⇒ Object
- #store(archive_name, metadata) ⇒ Object
Constructor Details
#initialize(repo_path) ⇒ ArchiveCache
Returns a new instance of ArchiveCache.
16 17 18 19 20 21 |
# File 'lib/ruborg/archive_cache.rb', line 16 def initialize(repo_path) @repo_path = repo_path @data = {} @snapshot = {} @loaded = false end |
Instance Method Details
#[](archive_name) ⇒ Object
37 38 39 |
# File 'lib/ruborg/archive_cache.rb', line 37 def [](archive_name) @data[archive_name] end |
#entries ⇒ Object
Returns all cached entries as an array of hashes, each including :archive_name.
46 47 48 |
# File 'lib/ruborg/archive_cache.rb', line 46 def entries @data.map { |archive_name, | .merge(archive_name: archive_name) } end |
#fetch ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruborg/archive_cache.rb', line 23 def fetch return self if @loaded if ssh? load_remote else load_local end @snapshot = snapshot(@data) @loaded = true self end |
#save_if_changed ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/ruborg/archive_cache.rb', line 50 def save_if_changed return unless dirty? if ssh? save_remote else save_local end end |
#store(archive_name, metadata) ⇒ Object
41 42 43 |
# File 'lib/ruborg/archive_cache.rb', line 41 def store(archive_name, ) @data[archive_name] = symbolize() end |