Class: AndOne::IgnoreFile

Inherits:
Object
  • Object
show all
Defined in:
lib/and_one/ignore_file.rb

Overview

Parses and matches against a .and_one_ignore file.

The file supports four types of rules:

# Lines starting with # are comments

# Ignore N+1s originating from a specific gem
gem:devise
gem:administrate

# Ignore N+1s whose call stack matches a path pattern (supports * globs)
path:app/views/admin/*
path:lib/legacy/**

# Ignore N+1s matching a SQL pattern
query:schema_migrations
query:pg_catalog

# Ignore a specific detection by its fingerprint (shown in output)
fingerprint:abc123def456

Defined Under Namespace

Classes: Rule

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ IgnoreFile

Returns a new instance of IgnoreFile.



30
31
32
33
34
# File 'lib/and_one/ignore_file.rb', line 30

def initialize(path = nil)
  @path = path
  @rules = []
  parse if @path && File.exist?(@path)
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



28
29
30
# File 'lib/and_one/ignore_file.rb', line 28

def rules
  @rules
end

Instance Method Details

#ignored?(detection, raw_caller_strings) ⇒ Boolean

Check if a detection should be ignored. raw_caller_strings: the UN-cleaned caller locations (full paths, including gems) detection: the Detection object

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/and_one/ignore_file.rb', line 39

def ignored?(detection, raw_caller_strings)
  return false if @rules.empty?

  @rules.any? { |rule| matches?(rule, detection, raw_caller_strings) }
end