database_consistency 1.1.14 → 1.1.15

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: 86037a5780e8f5f906a5232a9925b5e250177b6ebe653a81509167814dc87a2e
4
- data.tar.gz: 91cafa728a48dd765a2b66fc41c9a2a4f2952d72737472c6f1f88af28d9053b8
3
+ metadata.gz: e7986728aea3224bf5a8f04ef65847f88bfe517b4c7b0b3b4361c7a0dbdd2a2d
4
+ data.tar.gz: d7225b7dadd93850c02c0282974dc01d4c8ae6c2ded3638e996d6aa3fe29fdbe
5
5
  SHA512:
6
- metadata.gz: d6ac7dbf5de3cc1cbfaa7aef08e86aad7c88b2e5734283ef130ab60582945312faf87828b949d6f2f2e551b2770faca8498ad70e6438bcc6416977df20441aa3
7
- data.tar.gz: f31f3a0ad600d45e7fcfe6f9d9aad07a267dfc96de990e03f7e725e9644f09d95ce8b6f0c69de920676e7023a5cf2dc7058dce2506f0ead2f23ee543b2596e8f
6
+ metadata.gz: ed7beed1d43e74309e173bfba69ebb82dc4948b73b31413c43d7454a4f3c165ef68328d902278bf8e1bf527897da9848213f477779f3a48d198a580a17b8f9ef
7
+ data.tar.gz: 0f00c0005e59a6f374c58d25b3554405edf78eb592908603b46224ca7aff86c0e9d39e2a1bb642d6ea0a69100d8df0bf8564c184e8d3ee4b88f93cfdafa75fb1
@@ -7,6 +7,7 @@ module DatabaseConsistency
7
7
  attr_reader :model, :association
8
8
 
9
9
  def initialize(model, association)
10
+ super()
10
11
  @model = model
11
12
  @association = association
12
13
  end
@@ -19,7 +19,7 @@ module DatabaseConsistency
19
19
  # @param [Boolean] catch_errors
20
20
  #
21
21
  # @return [Hash, File, nil]
22
- def report(catch_errors = true)
22
+ def report(catch_errors: true)
23
23
  return unless preconditions
24
24
 
25
25
  @report ||= check
@@ -7,6 +7,7 @@ module DatabaseConsistency
7
7
  attr_reader :model, :column
8
8
 
9
9
  def initialize(model, column)
10
+ super()
10
11
  @model = model
11
12
  @column = column
12
13
  end
@@ -7,6 +7,7 @@ module DatabaseConsistency
7
7
  attr_reader :model, :index
8
8
 
9
9
  def initialize(model, index)
10
+ super()
10
11
  @model = model
11
12
  @index = index
12
13
  end
@@ -7,6 +7,7 @@ module DatabaseConsistency
7
7
  attr_reader :model, :attribute, :validator
8
8
 
9
9
  def initialize(model, attribute, validator)
10
+ super()
10
11
  @model = model
11
12
  @attribute = attribute
12
13
  @validator = validator
@@ -7,6 +7,7 @@ module DatabaseConsistency
7
7
  attr_reader :model, :attribute, :validators
8
8
 
9
9
  def initialize(model, attribute, validators)
10
+ super()
10
11
  @model = model
11
12
  @attribute = attribute
12
13
  @validators = validators.select(&method(:filter))
@@ -23,8 +23,10 @@ module DatabaseConsistency
23
23
 
24
24
  # Returns list of models to check
25
25
  def models
26
- ActiveRecord::Base.descendants.delete_if(&:abstract_class?).delete_if do |klass|
27
- !klass.connection.table_exists?(klass.table_name) || klass.name.include?('HABTM_')
26
+ ActiveRecord::Base.descendants.delete_if(&:abstract_class?).select do |klass|
27
+ klass.connection.table_exists?(klass.table_name) &&
28
+ !klass.name.include?('HABTM_') &&
29
+ project_klass?(klass)
28
30
  end
29
31
  end
30
32
 
@@ -35,6 +37,15 @@ module DatabaseConsistency
35
37
  end
36
38
  end
37
39
 
40
+ # @param klass [ActiveRecord::Base]
41
+ #
42
+ # @return [Boolean]
43
+ def project_klass?(klass)
44
+ return true unless Module.respond_to?(:const_source_location) && defined?(Bundler)
45
+
46
+ !Module.const_source_location(klass.to_s).first.to_s.include?(Bundler.bundle_path.to_s)
47
+ end
48
+
38
49
  # @return [Boolean]
39
50
  def check_inclusion?(array, element)
40
51
  array.include?(element.to_s) || array.include?(element.to_sym)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.1.14'
4
+ VERSION = '1.1.15'
5
5
  end
@@ -12,6 +12,12 @@ module DatabaseConsistency
12
12
  red: "\e[31m"
13
13
  }.freeze
14
14
 
15
+ COLOR_BY_STATUS = {
16
+ ok: :green,
17
+ warning: :yellow,
18
+ fail: :red
19
+ }.freeze
20
+
15
21
  def write
16
22
  results.each do |result|
17
23
  next unless write?(result.status)
@@ -31,11 +37,7 @@ module DatabaseConsistency
31
37
  end
32
38
 
33
39
  def status_text(result)
34
- color = case result.status
35
- when :ok then :green
36
- when :warning then :yellow
37
- when :fail then :red
38
- end
40
+ color = COLOR_BY_STATUS[result.status]
39
41
 
40
42
  colorize(result.status, color)
41
43
  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.1.14
4
+ version: 1.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-28 00:00:00.000000000 Z
11
+ date: 2022-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
201
  requirements: []
202
- rubygems_version: 3.0.3.1
202
+ rubygems_version: 3.1.6
203
203
  signing_key:
204
204
  specification_version: 4
205
205
  summary: Provide an easy way to check the consistency of the database constraints