database_consistency 1.1.6 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 482d9a79d349bbe6d49233cf8ffb05accbf61c9d30db72b8e2d9c5d5517602a6
4
- data.tar.gz: 14309f3ef7aab0e6aa0d20e4f9a0c0148a2be89e30d09235fb558cc55085d38d
3
+ metadata.gz: 2a742a08f374228e004b155fef15ec5ddaa23404c5aacf42b462eb2cb82ba09a
4
+ data.tar.gz: 8359e199cdbb89fc9d4b8700728bbef938d2d90a1474e4c2400c2aaa6d31f28f
5
5
  SHA512:
6
- metadata.gz: 7abe1d2b81e1f557b20da7c61a33c9fab8ebe709dd459e78ec16c4b088b3a457b094985428d72f882c6e946d028a444bfaf6aa1058764f03aef6bb54c2ecd89c
7
- data.tar.gz: d2b930d6d7a0f639c9f7f139f207d90df85af5409d918d77cf7f3c781602844220996eb3fef6639f0c490f33235efa74f92817a254eb5ee4930ec429c4a4c02d
6
+ metadata.gz: 962c814731ed2c85427e4b3e765df897c8cd8574f6075e3566e65b72af5effa370a14593019748ff9833a9658a0e55841219acdf3fe9caf212aa9db4bc426df3
7
+ data.tar.gz: df3aab9a1b6b5d5b2a815ad237b76ff3ffe127cd7921050c09a57e5f53e08087344ad5777224a603c52978382f6568c0c8a19c16038863cb759cac147bb7f9be
@@ -1,27 +1,52 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require_relative '../lib/database_consistency/configuration'
4
+
5
+ default_config = DatabaseConsistency::Configuration::DEFAULT_PATH
6
+
3
7
  if ARGV.include?('install')
4
- require_relative '../lib/database_consistency/configuration'
5
- config_filename = DatabaseConsistency::Configuration::CONFIGURATION_PATH
6
- file_exists = File.exists?(config_filename)
8
+ require 'pathname'
9
+
10
+ file_exists = File.exists?(default_config)
7
11
  rules = Pathname.new(__FILE__).dirname.join('..', 'lib', 'database_consistency', 'templates', 'rails_defaults.yml').read
8
- if file_exists && File.foreach(config_filename).grep(Regexp.new(rules.lines.first.chomp)).any?
9
- puts "#{config_filename} is already present"
12
+ if file_exists && File.foreach(default_config).grep(Regexp.new(rules.lines.first.chomp)).any?
13
+ puts "#{default_config} is already present"
10
14
  else
11
- File.open(config_filename, 'a') do |file|
15
+ File.open(default_config, 'a') do |file|
12
16
  file << "\n" * 2 if file_exists
13
17
  file << rules
14
18
  end
15
- puts "#{config_filename} #{file_exists ? 'updated' : 'added'}"
19
+ puts "#{default_config} #{file_exists ? 'updated' : 'added'}"
16
20
  end
17
21
  exit 0
18
- else
19
- base_dir = File.join(Dir.pwd, ARGV.first.to_s)
20
- unless File.realpath(base_dir).start_with?(Dir.pwd)
21
- puts "\nWarning! You are going out of current directory, ruby version may be wrong and some gems may be missing.\n"
22
+ end
23
+
24
+ require 'optparse'
25
+
26
+ config = [default_config]
27
+ opt_parser = OptionParser.new do |opts|
28
+ opts.banner = <<-DESC
29
+ Usage: database_consistency install - run installation
30
+ database_consistency [options]
31
+ DESC
32
+
33
+ opts.on('-cFILE', '--config=FILE', 'Use additional configuration file') do |f|
34
+ config << f
35
+ end
36
+
37
+ opts.on('-h', '--help', 'Prints this help') do
38
+ puts opts
39
+ exit
22
40
  end
23
41
  end
24
42
 
43
+ opt_parser.parse!
44
+
45
+ base_dir = File.join(Dir.pwd, ARGV.first.to_s)
46
+ unless File.realpath(base_dir).start_with?(Dir.pwd)
47
+ puts "\nWarning! You are going out of current directory, ruby version may be wrong and some gems may be missing.\n"
48
+ end
49
+
25
50
  # Load Rails project
26
51
  begin
27
52
  require File.join(base_dir, 'config', 'boot')
@@ -41,5 +66,5 @@ $LOAD_PATH.unshift(File.expand_path('lib', __dir__))
41
66
  require 'database_consistency'
42
67
 
43
68
  # Process checks
44
- code = DatabaseConsistency.run
69
+ code = DatabaseConsistency.run(config)
45
70
  exit code
@@ -5,15 +5,20 @@ require 'yaml'
5
5
  module DatabaseConsistency
6
6
  # The class to access configuration options
7
7
  class Configuration
8
- CONFIGURATION_PATH = '.database_consistency.yml'
9
-
10
- def initialize(filepath = CONFIGURATION_PATH)
11
- @configuration = if filepath && File.exist?(filepath)
12
- data = YAML.load_file(filepath)
13
- data.is_a?(Hash) ? data : {}
14
- else
15
- {}
16
- end
8
+ DEFAULT_PATH = '.database_consistency.yml'
9
+
10
+ def initialize(filepaths = DEFAULT_PATH)
11
+ @configuration = Array(filepaths).each_with_object({}) do |filepath, result|
12
+ content =
13
+ if filepath && File.exist?(filepath)
14
+ data = YAML.load_file(filepath)
15
+ data.is_a?(Hash) ? data : {}
16
+ else
17
+ {}
18
+ end
19
+
20
+ combine_configs!(result, content)
21
+ end
17
22
  end
18
23
 
19
24
  def debug?
@@ -48,6 +53,16 @@ module DatabaseConsistency
48
53
 
49
54
  attr_reader :configuration
50
55
 
56
+ def combine_configs!(config, new_config)
57
+ config.merge!(new_config) do |_key, val, new_val|
58
+ if val.is_a?(Hash) && new_val.is_a?(Hash)
59
+ combine_configs!(val, new_val)
60
+ else
61
+ new_val
62
+ end
63
+ end
64
+ end
65
+
51
66
  def settings
52
67
  @settings ||= configuration['DatabaseConsistencySettings']
53
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.1.6'
4
+ VERSION = '1.1.7'
5
5
  end
@@ -48,8 +48,8 @@ require 'database_consistency/processors/indexes_processor'
48
48
  # The root module
49
49
  module DatabaseConsistency
50
50
  class << self
51
- def run
52
- configuration = Configuration.new
51
+ def run(*args)
52
+ configuration = Configuration.new(*args)
53
53
  reports = Processors.reports(configuration)
54
54
 
55
55
  Writers::SimpleWriter.write(
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.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-10 00:00:00.000000000 Z
11
+ date: 2021-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord