Class: RubynCode::Skills::PackInstaller
- Inherits:
-
Object
- Object
- RubynCode::Skills::PackInstaller
- Defined in:
- lib/rubyn_code/skills/pack_installer.rb
Overview
Downloads and installs skill packs from the registry.
Handles ETag caching, version comparison, and offline fallback. Installs to ‘.rubyn-code/skills/<pack>/` (project) by default, or `~/.rubyn-code/skills/<pack>/` with the –global flag.
Constant Summary collapse
- MANIFEST_FILE =
'.manifest.json'
Instance Method Summary collapse
-
#initialize(registry_client:, project_root:, global: false) ⇒ PackInstaller
constructor
A new instance of PackInstaller.
-
#install(names, update: false) {|event, data| ... } ⇒ Array<Hash>
Install one or more packs by name.
-
#installed?(name) ⇒ Boolean
Check if a specific pack is installed.
-
#installed_packs ⇒ Array<Hash>
List installed packs with their metadata.
-
#read_manifest(name) ⇒ Hash?
Read the installed manifest for a pack.
-
#remove(name) ⇒ Boolean
Remove an installed pack.
-
#update_all {|event, data| ... } ⇒ Array<Hash>
Update all installed packs to their latest versions.
Constructor Details
#initialize(registry_client:, project_root:, global: false) ⇒ PackInstaller
Returns a new instance of PackInstaller.
19 20 21 22 23 |
# File 'lib/rubyn_code/skills/pack_installer.rb', line 19 def initialize(registry_client:, project_root:, global: false) @client = registry_client @project_root = project_root @global = global end |
Instance Method Details
#install(names, update: false) {|event, data| ... } ⇒ Array<Hash>
Install one or more packs by name.
33 34 35 |
# File 'lib/rubyn_code/skills/pack_installer.rb', line 33 def install(names, update: false, &block) names.map { |name| install_single(name, update: update, &block) } end |
#installed?(name) ⇒ Boolean
Check if a specific pack is installed.
76 77 78 |
# File 'lib/rubyn_code/skills/pack_installer.rb', line 76 def installed?(name) File.exist?(manifest_path(name)) end |
#installed_packs ⇒ Array<Hash>
List installed packs with their metadata.
63 64 65 66 67 68 69 70 |
# File 'lib/rubyn_code/skills/pack_installer.rb', line 63 def installed_packs dir = skills_base_dir return [] unless Dir.exist?(dir) Dir.children(dir) .select { |d| File.directory?(File.join(dir, d)) } .filter_map { |d| read_manifest(d) } end |
#read_manifest(name) ⇒ Hash?
Read the installed manifest for a pack.
84 85 86 87 88 89 90 91 |
# File 'lib/rubyn_code/skills/pack_installer.rb', line 84 def read_manifest(name) path = manifest_path(name) return nil unless File.exist?(path) JSON.parse(File.read(path)) rescue JSON::ParserError nil end |
#remove(name) ⇒ Boolean
Remove an installed pack.
52 53 54 55 56 57 58 |
# File 'lib/rubyn_code/skills/pack_installer.rb', line 52 def remove(name) dir = pack_dir(name) return false unless Dir.exist?(dir) FileUtils.rm_rf(dir) true end |
#update_all {|event, data| ... } ⇒ Array<Hash>
Update all installed packs to their latest versions.
41 42 43 44 45 46 |
# File 'lib/rubyn_code/skills/pack_installer.rb', line 41 def update_all(&block) installed = installed_packs return [] if installed.empty? installed.map { |pack| install_single(pack['name'], update: true, &block) } end |