Class: BundlerSkills::Linker

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler_skills/linker.rb

Overview

Creates idempotent absolute symlinks for discovered skills into a single output directory, and prunes stale ones we previously created.

Pure filesystem operations — no Bundler dependency, so it is fully unit testable against a tmpdir. One Linker instance == one output directory (e.g. .claude/skills or .agents/skills).

Defined Under Namespace

Classes: Result

Constant Summary collapse

STALE_GLOB =
"#{DiscoveredSkill::LINK_PREFIX}*#{DiscoveredSkill::BOUNDARY}*"

Instance Method Summary collapse

Constructor Details

#initialize(skills_dir:, config: Config.new(Config::DEFAULTS), logger: nil) ⇒ Linker

Returns a new instance of Linker.



27
28
29
30
31
# File 'lib/bundler_skills/linker.rb', line 27

def initialize(skills_dir:, config: Config.new(Config::DEFAULTS), logger: nil)
  @skills_dir = skills_dir
  @config = config
  @logger = logger
end

Instance Method Details

#clean_allArray<String>

Remove every gem- symlink we own (for ‘bundle skills clean`).

Returns:

  • (Array<String>)

    removed link names



47
48
49
50
51
52
53
54
55
56
# File 'lib/bundler_skills/linker.rb', line 47

def clean_all
  removed = []
  Dir.glob(File.join(@skills_dir, STALE_GLOB)).each do |path|
    next unless File.symlink?(path)

    remove(path)
    removed << File.basename(path)
  end
  removed
end

Parameters:

Returns:



35
36
37
38
39
40
41
42
43
# File 'lib/bundler_skills/linker.rb', line 35

def link(skills)
  result = Result.new
  link_names = skills.map(&:link_name)

  ensure_dir
  skills.each { |skill| link_one(skill, result) }
  prune_stale(link_names, result) if @config.cleanup?
  result
end