Class: BundlerSkills::Config
- Inherits:
-
Object
- Object
- BundlerSkills::Config
- 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:
enabled nil(auto) | true | false | [env names]
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 =
{ "enabled" => nil, "agents" => nil, "gitignore" => true, "cleanup" => true, "recursive" => false, "dry_run" => false, "force" => false, "include" => [], "exclude" => [] }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#agents ⇒ Object
nil (auto-detect) | Array<String>.
- #cleanup? ⇒ Boolean
- #dry_run? ⇒ Boolean
-
#enabled ⇒ Object
nil | true | false | Array<String>.
- #exclude_patterns ⇒ Object
- #force? ⇒ Boolean
- #gitignore? ⇒ Boolean
- #include_patterns ⇒ Object
-
#included?(gem_name, skill_name) ⇒ Boolean
include/exclude are matched against the gem name (and “gem/skill”) using File.fnmatch wildcards.
-
#initialize(data) ⇒ Config
constructor
A new instance of Config.
- #recursive? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ Config
Returns a new instance of Config.
48 49 50 |
# File 'lib/bundler_skills/config.rb', line 48 def initialize(data) @data = data end |
Class Method Details
.load(root: Bundler.root) ⇒ Object
31 32 33 34 35 |
# File 'lib/bundler_skills/config.rb', line 31 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
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bundler_skills/config.rb', line 37 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.}") if defined?(Bundler) {} end |
Instance Method Details
#agents ⇒ Object
nil (auto-detect) | Array<String>. A bare string key is wrapped so ‘agents: claude` works as well as a YAML list.
61 62 63 64 65 66 |
# File 'lib/bundler_skills/config.rb', line 61 def agents value = @data["agents"] return nil if value.nil? Array(value).map(&:to_s) end |
#cleanup? ⇒ Boolean
72 73 74 |
# File 'lib/bundler_skills/config.rb', line 72 def cleanup? @data["cleanup"] != false end |
#dry_run? ⇒ Boolean
80 81 82 |
# File 'lib/bundler_skills/config.rb', line 80 def dry_run? @data["dry_run"] == true end |
#enabled ⇒ Object
nil | true | false | Array<String>. A bare string env name is normalized to a one-element array so ‘enabled: development` behaves like a list.
54 55 56 57 |
# File 'lib/bundler_skills/config.rb', line 54 def enabled value = @data["enabled"] value.is_a?(String) ? [value] : value end |
#exclude_patterns ⇒ Object
92 93 94 |
# File 'lib/bundler_skills/config.rb', line 92 def exclude_patterns Array(@data["exclude"]).map(&:to_s) end |
#force? ⇒ Boolean
84 85 86 |
# File 'lib/bundler_skills/config.rb', line 84 def force? @data["force"] == true end |
#gitignore? ⇒ Boolean
68 69 70 |
# File 'lib/bundler_skills/config.rb', line 68 def gitignore? @data["gitignore"] != false end |
#include_patterns ⇒ Object
88 89 90 |
# File 'lib/bundler_skills/config.rb', line 88 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.
98 99 100 101 102 103 |
# File 'lib/bundler_skills/config.rb', line 98 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
76 77 78 |
# File 'lib/bundler_skills/config.rb', line 76 def recursive? @data["recursive"] == true end |