Class: Rubino::Util::IgnoreRules
- Inherits:
-
Object
- Object
- Rubino::Util::IgnoreRules
- Defined in:
- lib/rubino/util/ignore_rules.rb
Overview
Consistent .gitignore-aware file filtering shared by the grep Ruby fallback and the glob tool (#375b/#375c).
The PROBLEM: grep’s ripgrep path honors .gitignore, but the Ruby fallback (‘Dir.glob(“*/”)`) did not — so `grep` returned a DIFFERENT, larger set (including build artifacts, node_modules, secrets in ignored files) depending on whether rg happened to be installed. Non-deterministic, and a leak of ignored content. The glob tool ignored .gitignore entirely too.
The FIX: a single ignore oracle both non-rg paths consult, matching rg’s default semantics as closely as a non-rg implementation can:
* In a git repo, the canonical answer is `git ls-files --cached --others
--exclude-standard` (tracked + untracked-but-not-ignored) — EXACTLY
the set rg searches by default. We build the allowed-path set from it.
* Outside a repo (or if git fails), fall back to a small built-in
denylist of always-noise dirs (.git, node_modules, …) so behaviour is
still deterministic and never leaks the VCS internals.
Per-root results are cached for the life of the instance, so a single grep/glob call pays the git cost once.
Constant Summary collapse
- FALLBACK_IGNORE_DIRS =
Always-skipped dirs for the non-git fallback. Mirrors the set UI::CompletionSource uses so discovery is consistent across the tool.
%w[.git node_modules vendor tmp log .bundle .svn .hg __pycache__].freeze
Instance Method Summary collapse
-
#ignored?(abs_path, root) ⇒ Boolean
True when
abs_path(an absolute file path) should be EXCLUDED from results givenroot(the search base). -
#initialize ⇒ IgnoreRules
constructor
A new instance of IgnoreRules.
Constructor Details
#initialize ⇒ IgnoreRules
Returns a new instance of IgnoreRules.
33 34 35 36 |
# File 'lib/rubino/util/ignore_rules.rb', line 33 def initialize @allowed_cache = {} @git_root_cache = {} end |
Instance Method Details
#ignored?(abs_path, root) ⇒ Boolean
True when abs_path (an absolute file path) should be EXCLUDED from results given root (the search base). Consistent across grep-fallback and glob: a path git ignores (or the fallback denylist matches) is ignored regardless of whether rg is installed.
42 43 44 45 46 47 48 49 50 |
# File 'lib/rubino/util/ignore_rules.rb', line 42 def ignored?(abs_path, root) allowed = allowed_set(root) return fallback_ignored?(abs_path, root) if allowed.nil? rel = relative(abs_path, root) return true if rel.nil? !allowed.include?(rel) end |