Class: AgentsSkillVault::Manifest
- Inherits:
-
Object
- Object
- AgentsSkillVault::Manifest
- Defined in:
- lib/agents_skill_vault/manifest.rb
Overview
Manages the JSON manifest file that tracks all resources in a vault.
The manifest stores metadata about each resource including labels, URLs, and sync timestamps. It persists to disk as a JSON file.
Constant Summary collapse
- VERSION =
Current manifest file format version
"1.0"
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
Absolute path to the manifest JSON file.
Instance Method Summary collapse
-
#add_resource(resource) ⇒ void
Adds a new resource to the manifest.
-
#clear ⇒ void
Clears all resources from the manifest.
-
#find_resource(label, storage_path: nil) ⇒ Resource?
Finds a resource by its label.
-
#initialize(path:) ⇒ Manifest
constructor
Creates a new Manifest instance.
-
#load ⇒ Hash
Loads the manifest data from disk.
-
#remove_resource(label) ⇒ void
Removes a resource from the manifest by label.
-
#resources ⇒ Array<Hash>
Returns all resource hashes from the manifest.
-
#save(data) ⇒ void
Saves manifest data to disk.
-
#update_resource(resource) ⇒ Boolean
Updates an existing resource in the manifest.
Constructor Details
#initialize(path:) ⇒ Manifest
Creates a new Manifest instance.
27 28 29 |
# File 'lib/agents_skill_vault/manifest.rb', line 27 def initialize(path:) @path = path end |
Instance Attribute Details
#path ⇒ String (readonly)
Returns Absolute path to the manifest JSON file.
21 22 23 |
# File 'lib/agents_skill_vault/manifest.rb', line 21 def path @path end |
Instance Method Details
#add_resource(resource) ⇒ void
This method returns an undefined value.
Adds a new resource to the manifest.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/agents_skill_vault/manifest.rb', line 64 def add_resource(resource) data = load data[:resources] ||= [] if data[:resources].any? { |r| r[:label] == resource.label } raise Errors::DuplicateLabel, "Resource with label '#{resource.label}' already exists. " \ "Use a custom label with: add(url, label: 'custom-label')" end data[:resources] << resource.to_h save(data) end |
#clear ⇒ void
This method returns an undefined value.
Clears all resources from the manifest.
124 125 126 |
# File 'lib/agents_skill_vault/manifest.rb', line 124 def clear save(default_manifest) end |
#find_resource(label, storage_path: nil) ⇒ Resource?
Finds a resource by its label.
113 114 115 116 117 118 |
# File 'lib/agents_skill_vault/manifest.rb', line 113 def find_resource(label, storage_path: nil) hash = resources.find { |r| r[:label] == label } return nil unless hash Resource.from_h(hash, storage_path: storage_path || storage_path_from_manifest) end |
#load ⇒ Hash
Loads the manifest data from disk.
35 36 37 38 39 |
# File 'lib/agents_skill_vault/manifest.rb', line 35 def load return default_manifest unless File.exist?(path) JSON.parse(File.read(path), symbolize_names: true) end |
#remove_resource(label) ⇒ void
This method returns an undefined value.
Removes a resource from the manifest by label.
Does nothing if the label doesn't exist (no error raised).
84 85 86 87 88 |
# File 'lib/agents_skill_vault/manifest.rb', line 84 def remove_resource(label) data = load data[:resources]&.reject! { |r| r[:label] == label } save(data) end |
#resources ⇒ Array<Hash>
Returns all resource hashes from the manifest.
54 55 56 |
# File 'lib/agents_skill_vault/manifest.rb', line 54 def resources load[:resources] || [] end |
#save(data) ⇒ void
This method returns an undefined value.
Saves manifest data to disk.
46 47 48 |
# File 'lib/agents_skill_vault/manifest.rb', line 46 def save(data) File.write(path, JSON.pretty_generate(data)) end |
#update_resource(resource) ⇒ Boolean
Updates an existing resource in the manifest.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/agents_skill_vault/manifest.rb', line 95 def update_resource(resource) # rubocop:disable Naming/PredicateMethod data = load data[:resources] ||= [] index = data[:resources].find_index { |r| r[:label] == resource.label } return false unless index data[:resources][index] = resource.to_h save(data) true end |