class Querly::Config

Attributes

checks[R]
preprocessors[R]
root_dir[R]
rules[R]
rules_cache[R]

Public Class Methods

load(hash, config_path:, root_dir:, stderr: STDERR) click to toggle source
# File lib/querly/config.rb, line 17
def self.load(hash, config_path:, root_dir:, stderr: STDERR)
  Factory.new(hash, config_path: config_path, root_dir: root_dir, stderr: stderr).config
end
new(rules:, preprocessors:, root_dir:, checks:) click to toggle source
# File lib/querly/config.rb, line 9
def initialize(rules:, preprocessors:, root_dir:, checks:)
  @rules = rules
  @root_dir = root_dir
  @preprocessors = preprocessors
  @checks = checks
  @rules_cache = {}
end

Public Instance Methods

all_rules() click to toggle source
# File lib/querly/config.rb, line 21
def all_rules
  @all_rules ||= Set.new(rules)
end
relative_path_from_root(path) click to toggle source
# File lib/querly/config.rb, line 25
def relative_path_from_root(path)
  path.absolute? ? path.relative_path_from(root_dir) : path.cleanpath
end
rules_for_path(path) click to toggle source
# File lib/querly/config.rb, line 29
def rules_for_path(path)
  relative_path = relative_path_from_root(path)
  matching_checks = checks.select {|check| check.match?(path: relative_path) }

  if rules_cache.key?(matching_checks)
    rules_cache[matching_checks]
  else
    matching_checks.flat_map(&:rules).inject(all_rules) do |rules, query|
      query.apply(current: rules, all: all_rules)
    end.tap do |rules|
      rules_cache[matching_checks] = rules
    end
  end
end