database_consistency 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/database_consistency.rb +3 -1
- data/lib/database_consistency/checkers/{validator_checkers → validators_fraction_checkers}/column_presence_checker.rb +8 -4
- data/lib/database_consistency/checkers/validators_fraction_checkers/validators_fraction_checker.rb +26 -0
- data/lib/database_consistency/processors/base_processor.rb +2 -1
- data/lib/database_consistency/processors/validators_fractions_processor.rb +30 -0
- data/lib/database_consistency/processors/validators_processor.rb +0 -1
- data/lib/database_consistency/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 149d7592b96f1f028881570c9fc3d4c25205361758eaa81de99ee583efad3cab
|
4
|
+
data.tar.gz: 1337cc3b1c115f660906663ee975afedc57308c48cc6b53d02cb6cc52494e8d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1f1c9f3d7b598ea7a2d9c0656aed100e8dc3d685316914f769f77f462c49b39541d6aea53552ef123cc05a0b5b6c01750e2951f7b7bd4495a9ddf42b0b76ba2
|
7
|
+
data.tar.gz: 9c781f382b1cbb7180daf21788648d0afd68f581132e69456a3c34a9580d3bc1d0bf85ed4dce8007cb8922fe9a7222efac4b624f56ea87d48c5315931d476603
|
data/lib/database_consistency.rb
CHANGED
@@ -17,14 +17,16 @@ require 'database_consistency/checkers/column_checkers/column_checker'
|
|
17
17
|
require 'database_consistency/checkers/column_checkers/null_constraint_checker'
|
18
18
|
require 'database_consistency/checkers/column_checkers/length_constraint_checker'
|
19
19
|
require 'database_consistency/checkers/validator_checkers/validator_checker'
|
20
|
-
require 'database_consistency/checkers/validator_checkers/column_presence_checker'
|
21
20
|
require 'database_consistency/checkers/validator_checkers/belongs_to_presence_checker'
|
22
21
|
require 'database_consistency/checkers/validator_checkers/missing_unique_index_checker'
|
22
|
+
require 'database_consistency/checkers/validators_fraction_checkers/validators_fraction_checker'
|
23
|
+
require 'database_consistency/checkers/validators_fraction_checkers/column_presence_checker'
|
23
24
|
|
24
25
|
require 'database_consistency/processors/base_processor'
|
25
26
|
require 'database_consistency/processors/associations_processor'
|
26
27
|
require 'database_consistency/processors/validators_processor'
|
27
28
|
require 'database_consistency/processors/columns_processor'
|
29
|
+
require 'database_consistency/processors/validators_fractions_processor'
|
28
30
|
|
29
31
|
# The root module
|
30
32
|
module DatabaseConsistency
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module DatabaseConsistency
|
4
4
|
module Checkers
|
5
5
|
# This class checks if presence validator has non-null constraint in the database
|
6
|
-
class ColumnPresenceChecker <
|
6
|
+
class ColumnPresenceChecker < ValidatorsFractionChecker
|
7
7
|
WEAK_OPTIONS = %i[allow_nil allow_blank if unless].freeze
|
8
8
|
# Message templates
|
9
9
|
CONSTRAINT_MISSING = 'column should be required in the database'
|
@@ -11,11 +11,15 @@ module DatabaseConsistency
|
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
+
def filter(validator)
|
15
|
+
validator.kind == :presence
|
16
|
+
end
|
17
|
+
|
14
18
|
# We skip check when:
|
15
|
-
# -
|
19
|
+
# - there is no presence validators
|
16
20
|
# - there is no column in the database with given name
|
17
21
|
def preconditions
|
18
|
-
|
22
|
+
validators.any? && column
|
19
23
|
end
|
20
24
|
|
21
25
|
# Table of possible statuses
|
@@ -27,7 +31,7 @@ module DatabaseConsistency
|
|
27
31
|
# | all missing | optional | fail |
|
28
32
|
def check
|
29
33
|
can_be_null = column.null
|
30
|
-
has_weak_option = validator.options.slice(*WEAK_OPTIONS).any?
|
34
|
+
has_weak_option = validators.all? { |validator| validator.options.slice(*WEAK_OPTIONS).any? }
|
31
35
|
|
32
36
|
if can_be_null == has_weak_option
|
33
37
|
report_template(:ok)
|
data/lib/database_consistency/checkers/validators_fraction_checkers/validators_fraction_checker.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Checkers
|
5
|
+
# The base class for validator checker
|
6
|
+
class ValidatorsFractionChecker < BaseChecker
|
7
|
+
attr_reader :model, :attribute, :validators
|
8
|
+
|
9
|
+
def initialize(model, attribute, validators)
|
10
|
+
@model = model
|
11
|
+
@attribute = attribute
|
12
|
+
@validators = validators.select(&method(:filter))
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [String]
|
16
|
+
def column_or_attribute_name
|
17
|
+
@column_or_attribute_name ||= attribute.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String]
|
21
|
+
def table_or_model_name
|
22
|
+
@table_or_model_name ||= model.name.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseConsistency
|
4
|
+
module Processors
|
5
|
+
# The class to process validators
|
6
|
+
class ValidatorsFractionsProcessor < BaseProcessor
|
7
|
+
CHECKERS = [
|
8
|
+
Checkers::ColumnPresenceChecker
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# @return [Array<Hash>]
|
14
|
+
def check
|
15
|
+
Helper.parent_models.flat_map do |model|
|
16
|
+
next unless configuration.enabled?(model)
|
17
|
+
|
18
|
+
model._validators.flat_map do |attribute, validators|
|
19
|
+
next unless attribute
|
20
|
+
|
21
|
+
enabled_checkers.map do |checker_class|
|
22
|
+
checker = checker_class.new(model, attribute, validators)
|
23
|
+
checker.report_if_enabled?(configuration)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end.compact
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_consistency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -139,14 +139,16 @@ files:
|
|
139
139
|
- lib/database_consistency/checkers/column_checkers/length_constraint_checker.rb
|
140
140
|
- lib/database_consistency/checkers/column_checkers/null_constraint_checker.rb
|
141
141
|
- lib/database_consistency/checkers/validator_checkers/belongs_to_presence_checker.rb
|
142
|
-
- lib/database_consistency/checkers/validator_checkers/column_presence_checker.rb
|
143
142
|
- lib/database_consistency/checkers/validator_checkers/missing_unique_index_checker.rb
|
144
143
|
- lib/database_consistency/checkers/validator_checkers/validator_checker.rb
|
144
|
+
- lib/database_consistency/checkers/validators_fraction_checkers/column_presence_checker.rb
|
145
|
+
- lib/database_consistency/checkers/validators_fraction_checkers/validators_fraction_checker.rb
|
145
146
|
- lib/database_consistency/configuration.rb
|
146
147
|
- lib/database_consistency/helper.rb
|
147
148
|
- lib/database_consistency/processors/associations_processor.rb
|
148
149
|
- lib/database_consistency/processors/base_processor.rb
|
149
150
|
- lib/database_consistency/processors/columns_processor.rb
|
151
|
+
- lib/database_consistency/processors/validators_fractions_processor.rb
|
150
152
|
- lib/database_consistency/processors/validators_processor.rb
|
151
153
|
- lib/database_consistency/rescue_error.rb
|
152
154
|
- lib/database_consistency/version.rb
|