database_consistency 1.7.24 → 1.7.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b29d0d23f3eda8be6c71719df374c21bf7c69f749bdd5d9e71b658b7194e0a7a
4
- data.tar.gz: 4dc387034661a53ce80a65513696da3bb5264b4097d1928268ca2cced6a2b082
3
+ metadata.gz: 6a60adb5b04de89499434019dd7ae4d0281799fc457122de1d01ad825d9d74e1
4
+ data.tar.gz: 3cfe216adacba3de2df73bf8cc353ce56bbdae93c0b4ada74b860cd89422f173
5
5
  SHA512:
6
- metadata.gz: 55f5c65ea75f3384bac11404204522c850d4637c884a6d08cc2b00201e874f74b246410527f6d619e41e35ef078bcca1f7dfce34709621a0a9d4c463b46d727f
7
- data.tar.gz: 6bf767f48dfb95cbfce02f9a0fe49718adff8c2afc2e7ae7d74b9496b7991f11bc9f4da10c682cb36dbab310b92c7afc01f9b0b0073c03adaa51000f3f4d216d
6
+ metadata.gz: d522414bc1680d596f9207c95615265befd75535e145c43bd7056c823a160a3620e4a9f5ce28b04b0d00878349e8a21d5b58fda669b6510bd714a355791aa8c6
7
+ data.tar.gz: be1853d66bf896d3ab6eae46684e8533177d90394de2d7360e2e613a3b61e050578fdd0b48a1b357c26171b4c14fedf54f74f064ba0854bdb17026730e2b58a9
@@ -48,6 +48,10 @@ module DatabaseConsistency
48
48
  value
49
49
  end
50
50
 
51
+ def model_enabled?(model)
52
+ database_enabled?(Helper.database_name(model)) && enabled?(model.name.to_s)
53
+ end
54
+
51
55
  def database_enabled?(name)
52
56
  value = configuration.dig('DatabaseConsistencyDatabases', name, 'enabled')
53
57
 
@@ -29,17 +29,19 @@ module DatabaseConsistency
29
29
  end
30
30
  end
31
31
 
32
- def project_models
32
+ def project_models(configuration)
33
33
  ActiveRecord::Base.descendants.select do |klass|
34
+ next unless configuration.model_enabled?(klass)
35
+
34
36
  project_klass?(klass) && connected?(klass)
35
37
  end
36
38
  end
37
39
 
38
40
  # Returns list of models to check
39
- def models
40
- project_models.select do |klass|
41
+ def models(configuration)
42
+ project_models(configuration).select do |klass|
41
43
  !klass.abstract_class? &&
42
- klass.connection.table_exists?(klass.table_name) &&
44
+ klass.table_exists? &&
43
45
  !klass.name.include?('HABTM_')
44
46
  end
45
47
  end
@@ -52,8 +54,8 @@ module DatabaseConsistency
52
54
  end
53
55
 
54
56
  # Return list of not inherited models
55
- def parent_models
56
- models.group_by(&:table_name).each_value.flat_map do |models|
57
+ def parent_models(configuration)
58
+ models(configuration).group_by(&:table_name).each_value.flat_map do |models|
57
59
  models.reject { |model| models.include?(model.superclass) }
58
60
  end
59
61
  end
@@ -65,6 +67,8 @@ module DatabaseConsistency
65
67
  return true unless Module.respond_to?(:const_source_location) && defined?(Bundler)
66
68
 
67
69
  !Module.const_source_location(klass.to_s).first.to_s.include?(Bundler.bundle_path.to_s)
70
+ rescue NameError
71
+ false
68
72
  end
69
73
 
70
74
  # @return [Boolean]
@@ -15,10 +15,8 @@ module DatabaseConsistency
15
15
  private
16
16
 
17
17
  def check # rubocop:disable Metrics/MethodLength
18
- Helper.models.flat_map do |model|
18
+ Helper.models(configuration).flat_map do |model|
19
19
  DebugContext.with(model: model.name) do
20
- next unless model_enabled?(model)
21
-
22
20
  Helper.first_level_associations(model).flat_map do |association|
23
21
  DebugContext.with(association: association.name) do
24
22
  enabled_checkers.flat_map do |checker_class|
@@ -43,11 +43,6 @@ module DatabaseConsistency
43
43
 
44
44
  private
45
45
 
46
- def model_enabled?(model)
47
- configuration.database_enabled?(Helper.database_name(model)) &&
48
- configuration.enabled?(model.name.to_s)
49
- end
50
-
51
46
  def check
52
47
  raise NotImplementedError
53
48
  end
@@ -16,10 +16,8 @@ module DatabaseConsistency
16
16
  private
17
17
 
18
18
  def check # rubocop:disable Metrics/MethodLength
19
- Helper.parent_models.flat_map do |model|
19
+ Helper.parent_models(configuration).flat_map do |model|
20
20
  DebugContext.with(model: model.name) do
21
- next unless model_enabled?(model)
22
-
23
21
  model.columns.flat_map do |column|
24
22
  DebugContext.with(column: column.name) do
25
23
  enabled_checkers.flat_map do |checker_class|
@@ -11,10 +11,8 @@ module DatabaseConsistency
11
11
  private
12
12
 
13
13
  def check # rubocop:disable Metrics/MethodLength
14
- Helper.models.flat_map do |model|
14
+ Helper.models(configuration).flat_map do |model|
15
15
  DebugContext.with(model: model.name) do
16
- next unless model_enabled?(model)
17
-
18
16
  model.defined_enums.keys.flat_map do |enum|
19
17
  DebugContext.with(enum: enum) do
20
18
  enabled_checkers.flat_map do |checker_class|
@@ -13,10 +13,8 @@ module DatabaseConsistency
13
13
  private
14
14
 
15
15
  def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
16
- Helper.parent_models.flat_map do |model|
16
+ Helper.parent_models(configuration).flat_map do |model|
17
17
  DebugContext.with(model: model.name) do
18
- next unless model_enabled?(model)
19
-
20
18
  indexes = model.connection.indexes(model.table_name)
21
19
 
22
20
  indexes.flat_map do |index|
@@ -11,10 +11,8 @@ module DatabaseConsistency
11
11
  private
12
12
 
13
13
  def check
14
- Helper.project_models.flat_map do |model|
14
+ Helper.project_models(configuration).flat_map do |model|
15
15
  DebugContext.with(model: model.name) do
16
- next unless model_enabled?(model)
17
-
18
16
  enabled_checkers.flat_map do |checker_class|
19
17
  DebugContext.with(checker: checker_class) do
20
18
  checker = checker_class.new(model)
@@ -12,10 +12,8 @@ module DatabaseConsistency
12
12
 
13
13
  # @return [Array<Hash>]
14
14
  def check # rubocop:disable Metrics/MethodLength
15
- Helper.parent_models.flat_map do |model|
15
+ Helper.parent_models(configuration).flat_map do |model|
16
16
  DebugContext.with(model: model.name) do
17
- next unless model_enabled?(model)
18
-
19
17
  model._validators.flat_map do |attribute, validators|
20
18
  DebugContext.with(attribute: attribute) do
21
19
  next unless attribute
@@ -13,10 +13,8 @@ module DatabaseConsistency
13
13
 
14
14
  # @return [Array<Hash>]
15
15
  def check # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
16
- Helper.parent_models.flat_map do |model|
16
+ Helper.parent_models(configuration).flat_map do |model|
17
17
  DebugContext.with(model: model.name) do
18
- next unless model_enabled?(model)
19
-
20
18
  model.validators.flat_map do |validator|
21
19
  next unless validator.respond_to?(:attributes)
22
20
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.7.24'
4
+ VERSION = '1.7.25'
5
5
  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: 1.7.24
4
+ version: 1.7.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-22 00:00:00.000000000 Z
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -126,14 +126,14 @@ dependencies:
126
126
  name: sqlite3
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">"
130
130
  - !ruby/object:Gem::Version
131
131
  version: '1.3'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '1.3'
139
139
  description: