Class: BundlerSkills::Config

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

Overview

Loads bundler-skills.yml and merges it with defaults.

The file is optional: a missing file yields an all-defaults Config so the hook works out of the box. Supported keys:

agents     nil(auto-detect) | "*" | [keys] | "key"
gitignore  bool (default true)
cleanup    bool (default true) — prune stale gem-*--* links
recursive  bool (default false) — scan skills/**/SKILL.md
include    [patterns]  — fnmatch on gem name or "gem/skill"
exclude    [patterns]  — same, wins over include
dry_run / force  bool

Constant Summary collapse

CONFIG_FILENAME =
"bundler-skills.yml"
DEFAULTS =
{
  "agents" => nil,
  "gitignore" => true,
  "cleanup" => true,
  "recursive" => false,
  "dry_run" => false,
  "force" => false,
  "include" => [],
  "exclude" => []
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Config

Returns a new instance of Config.



46
47
48
# File 'lib/bundler_skills/config.rb', line 46

def initialize(data)
  @data = data
end

Class Method Details

.load(root: Bundler.root) ⇒ Object



29
30
31
32
33
# File 'lib/bundler_skills/config.rb', line 29

def self.load(root: Bundler.root)
  path = File.join(root.to_s, CONFIG_FILENAME)
  data = read_yaml(path)
  new(DEFAULTS.merge(data))
end

.read_yaml(path) ⇒ Object



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

def self.read_yaml(path)
  return {} unless File.file?(path)

  require "yaml"
  loaded = YAML.safe_load_file(path)
  loaded.is_a?(Hash) ? loaded : {}
rescue StandardError => e
  Bundler.ui.warn("[bundler-skills] failed to read #{path}: #{e.message}") if defined?(Bundler)
  {}
end

Instance Method Details

#agentsObject

nil (auto-detect) | Array<String>. A bare string key is wrapped so ‘agents: claude` works as well as a YAML list.



52
53
54
55
56
57
# File 'lib/bundler_skills/config.rb', line 52

def agents
  value = @data["agents"]
  return nil if value.nil?

  Array(value).map(&:to_s)
end

#cleanup?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/bundler_skills/config.rb', line 63

def cleanup?
  @data["cleanup"] != false
end

#dry_run?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/bundler_skills/config.rb', line 71

def dry_run?
  @data["dry_run"] == true
end

#exclude_patternsObject



83
84
85
# File 'lib/bundler_skills/config.rb', line 83

def exclude_patterns
  Array(@data["exclude"]).map(&:to_s)
end

#force?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/bundler_skills/config.rb', line 75

def force?
  @data["force"] == true
end

#gitignore?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/bundler_skills/config.rb', line 59

def gitignore?
  @data["gitignore"] != false
end

#include_patternsObject



79
80
81
# File 'lib/bundler_skills/config.rb', line 79

def include_patterns
  Array(@data["include"]).map(&:to_s)
end

#included?(gem_name, skill_name) ⇒ Boolean

include/exclude are matched against the gem name (and “gem/skill”) using File.fnmatch wildcards. Empty include = allow all; exclude wins.

Returns:

  • (Boolean)


89
90
91
92
93
94
# File 'lib/bundler_skills/config.rb', line 89

def included?(gem_name, skill_name)
  return false if matches_any?(exclude_patterns, gem_name, skill_name)
  return true if include_patterns.empty?

  matches_any?(include_patterns, gem_name, skill_name)
end

#recursive?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/bundler_skills/config.rb', line 67

def recursive?
  @data["recursive"] == true
end