database_consistency 1.7.10 → 1.7.12

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: 672d4b81b5aa399e767e013289f7b7c5242fa60d4e6bb2776cbc62cfd56afd08
4
- data.tar.gz: e044d16e669c3f3f32f5a8076632848ea0bcd7ebee9f40dd015de8168dea177f
3
+ metadata.gz: 8560e4cc5588b8182f8d5258703894839190a758abf57e35e2abe81a630848fc
4
+ data.tar.gz: 26b96205cd47d48f9a557d6986ef2d2f0eef940f1407ed430760f6201c91cca5
5
5
  SHA512:
6
- metadata.gz: d908a7880fa77d923569d67f46c8129ba26348e26beaf73f3fe4e3a2d35cf2d31a2053321063c423d6e166453b577fb04048ec5d1056c11f6324a98168d202f9
7
- data.tar.gz: 00615f95cbe9d16a3578b3ab0568d06c0a779f442d3e4bc2402be3ddd7a9c52f748fe04c67cec027c0b937c508932b415b2acc9f4d9d4fa3f6d45ff14d37a4c2
6
+ metadata.gz: bfb1870b761338b23481926ec64cea7a814b7a174937d5035ca6a71ef63f7cfd332db6ab243f15ff5e9990a6445522b5565d2103b0c45eeb147f22eddbc48d7f
7
+ data.tar.gz: feec3a2004be04efe8ab1329a79b4b4395ffa3feec5c7798ad04b8218b7365b917a89a80681409d9a1827a5620105a7295ff6b67863828dd85b555c1dc8e7e7f
@@ -9,7 +9,11 @@ module DatabaseConsistency
9
9
 
10
10
  def initialize(file_paths = DEFAULT_PATH)
11
11
  @configuration = existing_configurations(file_paths).then do |existing_paths|
12
- puts "Loaded configurations: #{existing_paths.join(', ')}"
12
+ if existing_paths.any?
13
+ puts "Loaded configurations: #{existing_paths.join(', ')}"
14
+ else
15
+ puts 'No configurations were provided'
16
+ end
13
17
  extract_configurations(existing_paths)
14
18
  end
15
19
  end
@@ -33,7 +37,7 @@ module DatabaseConsistency
33
37
  value = global_enabling
34
38
 
35
39
  path.each do |key|
36
- current = current[key.to_s]
40
+ current = find(key.to_s, current)
37
41
  return value unless current.is_a?(Hash)
38
42
 
39
43
  next if current['enabled'].nil?
@@ -48,6 +52,16 @@ module DatabaseConsistency
48
52
 
49
53
  attr_reader :configuration
50
54
 
55
+ def find(key, configuration)
56
+ return configuration[key] if configuration.key?(key)
57
+
58
+ configuration.find { |(k, _)| k.include?('*') && key.match?(generate_regexp(k)) }&.last
59
+ end
60
+
61
+ def generate_regexp(str)
62
+ /\A#{str.gsub('*', '.*')}\z/
63
+ end
64
+
51
65
  def existing_configurations(paths)
52
66
  Array(paths).select do |filepath|
53
67
  filepath && File.exist?(filepath)
@@ -13,6 +13,10 @@ module DatabaseConsistency
13
13
  end
14
14
  end
15
15
 
16
+ def database_name(model)
17
+ model.connection_db_config.name.to_s if model.respond_to?(:connection_db_config)
18
+ end
19
+
16
20
  def postgresql?
17
21
  adapter == 'postgresql'
18
22
  end
@@ -13,9 +13,10 @@ module DatabaseConsistency
13
13
 
14
14
  private
15
15
 
16
- def check
16
+ def check # rubocop:disable Metrics/AbcSize
17
17
  Helper.models.flat_map do |model|
18
- next unless configuration.enabled?(model.name.to_s)
18
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
19
+ configuration.enabled?(model.name.to_s)
19
20
 
20
21
  Helper.first_level_associations(model).flat_map do |association|
21
22
  enabled_checkers.flat_map do |checker_class|
@@ -14,9 +14,10 @@ module DatabaseConsistency
14
14
 
15
15
  private
16
16
 
17
- def check
17
+ def check # rubocop:disable Metrics/AbcSize
18
18
  Helper.parent_models.flat_map do |model|
19
- next unless configuration.enabled?(model.name.to_s)
19
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
20
+ configuration.enabled?(model.name.to_s)
20
21
 
21
22
  model.columns.flat_map do |column|
22
23
  enabled_checkers.flat_map do |checker_class|
@@ -10,9 +10,10 @@ module DatabaseConsistency
10
10
 
11
11
  private
12
12
 
13
- def check
13
+ def check # rubocop:disable Metrics/AbcSize
14
14
  Helper.models.flat_map do |model|
15
- next unless configuration.enabled?(model.name.to_s)
15
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
16
+ configuration.enabled?(model.name.to_s)
16
17
 
17
18
  model.defined_enums.keys.flat_map do |enum|
18
19
  enabled_checkers.flat_map do |checker_class|
@@ -14,7 +14,8 @@ module DatabaseConsistency
14
14
 
15
15
  def check # rubocop:disable Metrics/AbcSize
16
16
  Helper.parent_models.flat_map do |model|
17
- next unless configuration.enabled?(model.name.to_s)
17
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
18
+ configuration.enabled?(model.name.to_s)
18
19
 
19
20
  indexes = model.connection.indexes(model.table_name)
20
21
 
@@ -11,9 +11,10 @@ module DatabaseConsistency
11
11
  private
12
12
 
13
13
  # @return [Array<Hash>]
14
- def check
14
+ def check # rubocop:disable Metrics/AbcSize
15
15
  Helper.parent_models.flat_map do |model|
16
- next unless configuration.enabled?(model.name.to_s)
16
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
17
+ configuration.enabled?(model.name.to_s)
17
18
 
18
19
  model._validators.flat_map do |attribute, validators|
19
20
  next unless attribute
@@ -12,9 +12,10 @@ module DatabaseConsistency
12
12
  private
13
13
 
14
14
  # @return [Array<Hash>]
15
- def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
15
+ def check # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
16
16
  Helper.parent_models.flat_map do |model|
17
- next unless configuration.enabled?(model.name.to_s)
17
+ next unless configuration.enabled?('DatabaseConsistencyDatabases', Helper.database_name(model)) &&
18
+ configuration.enabled?(model.name.to_s)
18
19
 
19
20
  model.validators.flat_map do |validator|
20
21
  next unless validator.respond_to?(:attributes)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.7.10'
4
+ VERSION = '1.7.12'
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.10
4
+ version: 1.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-24 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -264,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
264
  - !ruby/object:Gem::Version
265
265
  version: '0'
266
266
  requirements: []
267
- rubygems_version: 3.0.3.1
267
+ rubygems_version: 3.1.6
268
268
  signing_key:
269
269
  specification_version: 4
270
270
  summary: Provide an easy way to check the consistency of the database constraints