database_consistency 0.2.2 → 0.2.3

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: 93c3eb656f1f4ca77b34a647a612db82f713d624c672e7205a79ffc2c4715608
4
- data.tar.gz: 879befe9d7b24ae68f1ef492b9f32ae1e166c9d32ff9706bc0aebd68007d0511
3
+ metadata.gz: 6296221a3f6a0566aa3292762fbfb1c83673c9498e386a465049d08bb7fc6946
4
+ data.tar.gz: 8cfe97970a2eb4e4e579ac71fe4e3ba2b9169ca5e4b61a1473c45ab80d579b70
5
5
  SHA512:
6
- metadata.gz: bcb8edf4ae4fd959295dbdb1782c1f099c540b1c30d7d317da5f8164928502cd27666da9097059cbbfdc1f0ac060ed1ac90cab7aaf4cd6b2be683aad08c8010b
7
- data.tar.gz: a3ee3f2e85349980cad0d06e273ba77c889e5bd262b17df3dfb2fda5440b3aac97acf4e69e9287f5ea98b7368535de882031aeef73a3f2c98f54dd5294ba8c20
6
+ metadata.gz: 98314ca48f11a5ccb709d887d2ea28f29ce0c9100ba9489257195de86badcdf0a5bf145c2074ac679b99feb07105fcffc4f5f4ad1d8a3dacb1a58d7106136494
7
+ data.tar.gz: f5955ef7e7aaf2090f661c0165e3c2cdb09386a1463db92c0c716350875de1f324d0102ab7e8c247ae15f64d912a176ecb2cdfd682bccd6a9a60d171e35a724d
@@ -3,6 +3,7 @@ require 'active_record'
3
3
  require 'database_consistency/version'
4
4
  require 'database_consistency/report'
5
5
  require 'database_consistency/helper'
6
+ require 'database_consistency/configuration'
6
7
 
7
8
  require 'database_consistency/writers/base_writer'
8
9
  require 'database_consistency/writers/simple_writer'
@@ -17,17 +18,37 @@ require 'database_consistency/database_processor'
17
18
 
18
19
  # The root module
19
20
  module DatabaseConsistency
20
- def self.run
21
- Helper.load_environment!
22
-
23
- reports = [
24
- ValidatorsProcessor.new,
25
- DatabaseProcessor.new
26
- ].flat_map(&:reports)
27
-
28
- Writers::SimpleWriter.write(
29
- reports,
30
- ENV['LOG_LEVEL'] || 'INFO'
31
- )
21
+ CONFIGURATION_PATH = '.database_consistency.yml'.freeze
22
+
23
+ PROCESSORS = [
24
+ ValidatorsProcessor,
25
+ DatabaseProcessor
26
+ ].freeze
27
+
28
+ class << self
29
+ def run
30
+ Helper.load_environment!
31
+
32
+ Writers::SimpleWriter.write(
33
+ reports,
34
+ ENV['LOG_LEVEL'] || 'INFO'
35
+ )
36
+ end
37
+
38
+ def enabled_processors
39
+ PROCESSORS.select { |processor| configuration.enabled?(processor) }
40
+ end
41
+
42
+ def reports
43
+ enabled_processors.map(&:new).flat_map(&:reports)
44
+ end
45
+
46
+ def configuration
47
+ @configuration ||= if File.exist?(CONFIGURATION_PATH)
48
+ Configuration.new(CONFIGURATION_PATH)
49
+ else
50
+ Configuration.new
51
+ end
52
+ end
32
53
  end
33
54
  end
@@ -14,8 +14,13 @@ module DatabaseConsistency
14
14
 
15
15
  def skip?
16
16
  column.null ||
17
+ !column.default.nil? ||
17
18
  column.name == model.primary_key ||
18
- (model.record_timestamps? && %w[created_at updated_at].include?(column.name))
19
+ timestamp_field?
20
+ end
21
+
22
+ def timestamp_field?
23
+ model.record_timestamps? && %w[created_at updated_at].include?(column.name)
19
24
  end
20
25
 
21
26
  def presence_validator?
@@ -0,0 +1,19 @@
1
+ require 'yaml'
2
+
3
+ module DatabaseConsistency
4
+ # The class to access configuration options
5
+ class Configuration
6
+ def initialize(filepath = nil)
7
+ @configuration = if filepath
8
+ YAML.load_file(filepath)
9
+ else
10
+ {}
11
+ end
12
+ end
13
+
14
+ def enabled?(processor)
15
+ name = processor.to_s.split('::').last
16
+ @configuration[name].nil? || @configuration[name] == true
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module DatabaseConsistency
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  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.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-12 00:00:00.000000000 Z
11
+ date: 2018-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -114,6 +114,7 @@ files:
114
114
  - lib/database_consistency/column_verifiers/presence_missing_verifier.rb
115
115
  - lib/database_consistency/comparators/base_comparator.rb
116
116
  - lib/database_consistency/comparators/presence_comparator.rb
117
+ - lib/database_consistency/configuration.rb
117
118
  - lib/database_consistency/database_processor.rb
118
119
  - lib/database_consistency/helper.rb
119
120
  - lib/database_consistency/report.rb