Method: PathList::RuleGroups#initialize

Defined in:
lib/path_list/rule_groups.rb

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

:nocov:



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
38
39
40
41
# File 'lib/path_list/rule_groups.rb', line 9

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 = ::PathList::GitignoreRuleGroup.new(root)
    @array << @gitignore_rule_group
  end
  @array << ::PathList::RuleGroup.new(::PathList::Patterns.new(ignore_rules, root: root), false).freeze
  @array << ::PathList::RuleGroup.new(::PathList::Patterns.new(include_rules, root: root), true).freeze
  @array << ::PathList::RuleGroup.new(
    ::PathList::Patterns.new(argv_rules, root: root, format: :expand_path),
    true
  ).freeze

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