Class: BundlerSkills::GitignoreUpdater

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

Overview

Keeps a managed block in .gitignore listing the generated symlink patterns (e.g. .claude/skills/gem-*, .agents/skills/gem-*). The block is delimited by marker comments so it can be detected and rewritten without touching the rest of the file. Idempotent: re-running with the same patterns is a no-op.

Constant Summary collapse

BEGIN_MARKER =
"# >>> bundler-skills managed >>>"
END_MARKER =
"# <<< bundler-skills managed <<<"

Instance Method Summary collapse

Constructor Details

#initialize(gitignore_path:, dry_run: false) ⇒ GitignoreUpdater

Returns a new instance of GitignoreUpdater.



12
13
14
15
# File 'lib/bundler_skills/gitignore_updater.rb', line 12

def initialize(gitignore_path:, dry_run: false)
  @gitignore_path = gitignore_path
  @dry_run = dry_run
end

Instance Method Details

#ensure_patterns(patterns) ⇒ Boolean

Returns true when the file was changed (or would be, in dry-run).

Parameters:

  • patterns (Array<String>)

    e.g. [“.claude/skills/gem-*”]

Returns:

  • (Boolean)

    true when the file was changed (or would be, in dry-run)



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bundler_skills/gitignore_updater.rb', line 19

def ensure_patterns(patterns)
  patterns = patterns.uniq
  return false if patterns.empty?

  existing = File.exist?(@gitignore_path) ? File.read(@gitignore_path) : nil
  updated = rewrite(existing, patterns)
  return false if updated == existing

  File.write(@gitignore_path, updated) unless @dry_run
  true
end