Class: PgCanary::Rules::Base
- Inherits:
-
Object
- Object
- PgCanary::Rules::Base
show all
- Defined in:
- lib/pg_canary/rules/base.rb
Overview
Base class for detection rules.
A rule instance is built per analyzed query, holds that query's state,
and implements #check returning an array of Detection.
Direct Known Subclasses
ArraySearchWithoutGin, CartesianJoin, CorrelatedSubqueryInSelect, CountStarWithoutWhere, DeepOffset, DistinctWithJoin, FunctionOnColumn, HugeInList, ImplicitCast, JsonbSearchWithoutGin, LeadingWildcardLike, NotInSubquery, OrAcrossColumns, OrderByRandom, QueryComplexity, RegexWithoutTrgm, SelectStarWithHeavyColumns, UnindexedJoin, UnindexedOrderByWithLimit, UnindexedWhere, UnionInsteadOfUnionAll
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(sql:, config:, connection:, parse_result:, scopes:, binds: [], type_casted_binds: nil) ⇒ Base
Returns a new instance of Base.
50
51
52
53
54
55
56
57
58
|
# File 'lib/pg_canary/rules/base.rb', line 50
def initialize(sql:, config:, connection:, parse_result:, scopes:, binds: [], type_casted_binds: nil)
@sql = sql
@config = config
@connection = connection
@parse_result = parse_result
@scopes = scopes
@binds = binds || []
@type_casted_binds = type_casted_binds
end
|
Class Method Details
.all ⇒ Object
13
14
15
|
# File 'lib/pg_canary/rules/base.rb', line 13
def all
subclasses.sort_by(&:name)
end
|
.check(**state) ⇒ Object
45
46
47
|
# File 'lib/pg_canary/rules/base.rb', line 45
def check(**state)
new(**state).check
end
|
.default_enabled(value = nil) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/pg_canary/rules/base.rb', line 30
def default_enabled(value = nil)
if value.nil?
raise NotImplementedError, "#{self} must declare default_enabled" if @default_enabled.nil?
@default_enabled
else
@default_enabled = value
end
end
|
.enabled?(config) ⇒ Boolean
40
41
42
43
|
# File 'lib/pg_canary/rules/base.rb', line 40
def enabled?(config)
setting = config.rules.public_send(rule_name).enabled
setting.nil? ? default_enabled : setting
end
|
.option(name, default:) ⇒ Object
22
23
24
|
# File 'lib/pg_canary/rules/base.rb', line 22
def option(name, default:)
options[name] = default
end
|
.options ⇒ Object
26
27
28
|
# File 'lib/pg_canary/rules/base.rb', line 26
def options
@options ||= {}
end
|
.rule_name ⇒ Object
:leading_wildcard_like for LeadingWildcardLike
18
19
20
|
# File 'lib/pg_canary/rules/base.rb', line 18
def rule_name
@rule_name ||= name.demodulize.underscore.to_sym
end
|
Instance Method Details
#check ⇒ Object
60
61
62
|
# File 'lib/pg_canary/rules/base.rb', line 60
def check
raise NotImplementedError, "#{self.class} must implement #check"
end
|