Class: DatabaseConsistency::Checkers::BaseChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/database_consistency/checkers/base_checker.rb

Overview

The base class for checkers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.checker_nameString

Returns:

  • (String)


15
16
17
# File 'lib/database_consistency/checkers/base_checker.rb', line 15

def self.checker_name
  @checker_name ||= name.split('::').last
end

.enabled?(configuration) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


10
11
12
# File 'lib/database_consistency/checkers/base_checker.rb', line 10

def self.enabled?(configuration)
  configuration.enabled?('DatabaseConsistencyCheckers', checker_name)
end

Instance Method Details

#enabled?(configuration) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


40
41
42
# File 'lib/database_consistency/checkers/base_checker.rb', line 40

def enabled?(configuration)
  configuration.enabled?(table_or_model_name, column_or_attribute_name, checker_name)
end

#report(catch_errors: true) ⇒ Hash, ...

Parameters:

  • catch_errors (Boolean) (defaults to: true)

Returns:

  • (Hash, File, nil)


22
23
24
25
26
27
28
29
30
# File 'lib/database_consistency/checkers/base_checker.rb', line 22

def report(catch_errors: true)
  return unless preconditions

  @report ||= check
rescue StandardError => e
  raise e unless catch_errors

  RescueError.call(e)
end

#report_if_enabled?(configuration) ⇒ Hash, ...

Returns:

  • (Hash, File, nil)


33
34
35
# File 'lib/database_consistency/checkers/base_checker.rb', line 33

def report_if_enabled?(configuration)
  report if enabled?(configuration)
end