Class: FastIgnore::GitignoreRuleGroup

Inherits:
RuleGroup
  • Object
show all
Defined in:
lib/fast_ignore/gitignore_rule_group.rb

Instance Method Summary collapse

Methods inherited from RuleGroup

#allowed_recursive?, #allowed_unrecursive?, #empty?, #freeze, #weight

Constructor Details

#initialize(root) ⇒ GitignoreRuleGroup

Returns a new instance of GitignoreRuleGroup.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fast_ignore/gitignore_rule_group.rb', line 7

def initialize(root)
  @root = root
  @loaded_paths = Set[root]

  super([
    ::FastIgnore::Patterns.new('.git', root: '/'),
    ::FastIgnore::Patterns.new(from_file: ::FastIgnore::GlobalGitignore.path(root: root), root: root),
    ::FastIgnore::Patterns.new(from_file: "#{root}.git/info/exclude", root: root),
    ::FastIgnore::Patterns.new(from_file: "#{root}.gitignore", root: root)
  ], false)
end

Instance Method Details

#add_gitignore(dir) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/fast_ignore/gitignore_rule_group.rb', line 19

def add_gitignore(dir)
  return if @loaded_paths.include?(dir)

  @loaded_paths << dir
  matcher = ::FastIgnore::Patterns.new(from_file: "#{dir}.gitignore").build_matchers(allow: false)
  @matchers += matcher unless !matcher || matcher.empty?
end

#add_gitignore_to_root(path) ⇒ Object



27
28
29
# File 'lib/fast_ignore/gitignore_rule_group.rb', line 27

def add_gitignore_to_root(path)
  add_gitignore(path) until @loaded_paths.include?(path = "#{::File.dirname(path)}/")
end