Class: FastIgnore::RuleGroups

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

Instance Method Summary collapse

Constructor Details

#initialize(root:, ignore_rules: nil, ignore_files: nil, gitignore: true, include_rules: nil, include_files: nil, argv_rules: nil) ⇒ RuleGroups

rubocop:disable Metrics/ParameterLists, Metrics/AbcSize, Metrics/MethodLength



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fast_ignore/rule_groups.rb', line 5

def initialize( # rubocop:disable Metrics/ParameterLists, Metrics/AbcSize, Metrics/MethodLength
  root:,
  ignore_rules: nil,
  ignore_files: nil,
  gitignore: true,
  include_rules: nil,
  include_files: nil,
  argv_rules: nil
)
  @array = []
  if gitignore
    @gitignore_rule_group = ::FastIgnore::GitignoreRuleGroup.new(root)
    @array << @gitignore_rule_group
  end
  @array << ::FastIgnore::RuleGroup.new(::FastIgnore::Patterns.new(ignore_rules, root: root), false).freeze
  @array << ::FastIgnore::RuleGroup.new(::FastIgnore::Patterns.new(include_rules, root: root), true).freeze
  @array << ::FastIgnore::RuleGroup.new(
    ::FastIgnore::Patterns.new(argv_rules, root: root, format: :expand_path),
    true
  ).freeze

  Array(ignore_files).each do |f|
    path = PathExpander.expand_path(f, root)
    @array << ::FastIgnore::RuleGroup.new(::FastIgnore::Patterns.new(from_file: path), false).freeze
  end
  Array(include_files).each do |f|
    path = PathExpander.expand_path(f, root)
    @array << ::FastIgnore::RuleGroup.new(::FastIgnore::Patterns.new(from_file: path), true).freeze
  end
  @array.reject!(&:empty?)
  @array.sort_by!(&:weight)
  @array.freeze
end

Instance Method Details

#add_gitignore(dir) ⇒ Object



47
48
49
# File 'lib/fast_ignore/rule_groups.rb', line 47

def add_gitignore(dir)
  @gitignore_rule_group.add_gitignore(dir)
end

#add_gitignore_to_root(path) ⇒ Object



51
52
53
# File 'lib/fast_ignore/rule_groups.rb', line 51

def add_gitignore_to_root(path)
  @gitignore_rule_group.add_gitignore_to_root(path)
end

#allowed_recursive?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/fast_ignore/rule_groups.rb', line 39

def allowed_recursive?(candidate)
  @array.all? { |r| r.allowed_recursive?(candidate) }
end

#allowed_unrecursive?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/fast_ignore/rule_groups.rb', line 43

def allowed_unrecursive?(candidate)
  @array.all? { |r| r.allowed_unrecursive?(candidate) }
end