Class: RubynCode::Skills::PackInstaller

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(registry_client:, project_root:, global: false) ⇒ PackInstaller

Returns a new instance of PackInstaller.

Parameters:

  • registry_client (RegistryClient)
  • project_root (String)

    path to the project root

  • global (Boolean) (defaults to: false)

    install to ~/.rubyn-code/skills/ instead of project



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.

Parameters:

  • names (Array<String>)

    pack names

  • update (Boolean) (defaults to: false)

    update without prompting if already installed

Yields:

  • (event, data)

    progress events

Yield Parameters:

  • event (Symbol)

    :fetching, :downloading, :installed, :up_to_date, :error

  • data (Hash)

    event-specific data

Returns:

  • (Array<Hash>)

    results per pack ({ name:, status:, files: })



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.

Parameters:

  • name (String)

Returns:

  • (Boolean)


76
77
78
# File 'lib/rubyn_code/skills/pack_installer.rb', line 76

def installed?(name)
  File.exist?(manifest_path(name))
end

#installed_packsArray<Hash>

List installed packs with their metadata.

Returns:

  • (Array<Hash>)

    installed pack manifests



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.

Parameters:

  • name (String)

Returns:

  • (Hash, nil)


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.

Parameters:

  • name (String)

    pack name

Returns:

  • (Boolean)

    true if removed



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.

Yields:

  • (event, data)

    progress events

Returns:

  • (Array<Hash>)

    results per pack



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