Class: ActiveRecordDoctor::Detectors::Base
- Inherits:
-
Object
- Object
- ActiveRecordDoctor::Detectors::Base
show all
- Defined in:
- lib/active_record_doctor/detectors/base.rb
Overview
Base class for all active_record_doctor detectors.
Direct Known Subclasses
ExtraneousIndexes, IncorrectBooleanPresenceValidation, IncorrectDependentOption, IncorrectLengthValidation, MismatchedForeignKeyType, MissingForeignKeys, MissingNonNullConstraint, MissingPresenceValidation, MissingUniqueIndexes, ShortPrimaryKeyType, TableWithoutPrimaryKey, TableWithoutTimestamps, UndefinedTableReferences, UnindexedDeletedAt, UnindexedForeignKeys
Constant Summary
collapse
- BASE_CONFIG =
{
enabled: {
description: "set to false to disable the detector altogether"
}
}.freeze
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config:, logger:, io:) ⇒ Base
Returns a new instance of Base.
41
42
43
44
45
46
|
# File 'lib/active_record_doctor/detectors/base.rb', line 41
def initialize(config:, logger:, io:)
@problems = []
@config = config
@logger = logger
@io = io
end
|
Class Attribute Details
.description ⇒ Object
Returns the value of attribute description.
14
15
16
|
# File 'lib/active_record_doctor/detectors/base.rb', line 14
def description
@description
end
|
Class Method Details
.config ⇒ Object
24
25
26
|
# File 'lib/active_record_doctor/detectors/base.rb', line 24
def config
@config.merge(BASE_CONFIG)
end
|
.locals_and_globals ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/active_record_doctor/detectors/base.rb', line 28
def locals_and_globals
locals = []
globals = []
config.each do |key, metadata|
locals << key
globals << key if metadata[:global]
end
[locals, globals]
end
|
.run(*args, **kwargs, &block) ⇒ Object
16
17
18
|
# File 'lib/active_record_doctor/detectors/base.rb', line 16
def run(*args, **kwargs, &block)
new(*args, **kwargs, &block).run
end
|
.underscored_name ⇒ Object
20
21
22
|
# File 'lib/active_record_doctor/detectors/base.rb', line 20
def underscored_name
name.demodulize.underscore.to_sym
end
|
Instance Method Details
#run ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/active_record_doctor/detectors/base.rb', line 48
def run
log(underscored_name) do
@problems = []
if config(:enabled)
detect
else
log("disabled; skipping")
end
@problems.each do |problem|
@io.puts(message(**problem))
end
success = @problems.empty?
if success
log("No problems found")
else
log("Found #{@problems.count} problem(s)")
end
@problems = nil
success
end
end
|