Class: Goodcheck::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/goodcheck/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules:, exclude_paths:) ⇒ Config

Returns a new instance of Config.



6
7
8
9
# File 'lib/goodcheck/config.rb', line 6

def initialize(rules:, exclude_paths:)
  @rules = rules
  @exclude_paths = exclude_paths
end

Instance Attribute Details

#exclude_paths ⇒ Object (readonly)

Returns the value of attribute exclude_paths.



4
5
6
# File 'lib/goodcheck/config.rb', line 4

def exclude_paths
  @exclude_paths
end

#rules ⇒ Object (readonly)

Returns the value of attribute rules.



3
4
5
# File 'lib/goodcheck/config.rb', line 3

def rules
  @rules
end

Instance Method Details

#each_rule(filter:, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/goodcheck/config.rb', line 11

def each_rule(filter:, &block)
  if block_given?
    if filter.empty?
      rules.each(&block)
    else
      rules.each do |rule|
        if filter.any? {|rule_id| rule.id == rule_id || rule.id.start_with?("#{rule_id}.") }
          yield rule
        end
      end
    end
  else
    enum_for :each_rule, filter: filter
  end
end

#rules_for_path(path, rules_filter:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/goodcheck/config.rb', line 27

def rules_for_path(path, rules_filter:)
  if block_given?
    each_rule(filter: rules_filter).map do |rule|
      rule.triggers.each do |trigger|
        globs = trigger.globs

        if globs.empty?
          yield [rule, nil, trigger]
        else
          glob = globs.find {|glob| glob.test(path) }
          if glob
            yield [rule, glob, trigger]
          end
        end
      end
    end
  else
    enum_for(:rules_for_path, path, rules_filter: rules_filter)
  end
end