Class: DatabaseConsistency::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/database_consistency/configuration.rb

Overview

The class to access configuration options

Constant Summary collapse

DEFAULT_PATH =
'.database_consistency.yml'

Instance Method Summary collapse

Constructor Details

#initialize(file_paths = DEFAULT_PATH) ⇒ Configuration



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/database_consistency/configuration.rb', line 10

def initialize(file_paths = DEFAULT_PATH)
  existing_paths = existing_configurations(file_paths)

  if existing_paths.any?
    puts "Loaded configurations: #{existing_paths.join(', ')}"
  else
    puts 'No configurations were provided'
  end

  @configuration = extract_configurations(existing_paths)

  load_custom_checkers
end

Instance Method Details

#colored?Boolean



28
29
30
31
32
33
34
# File 'lib/database_consistency/configuration.rb', line 28

def colored?
  if ENV.key?('COLOR')
    ENV['COLOR'].match?(/1|true|yes/)
  else
    settings && settings['color']
  end
end

#database_enabled?(name) ⇒ Boolean



58
59
60
61
62
# File 'lib/database_consistency/configuration.rb', line 58

def database_enabled?(name)
  value = configuration.dig('DatabaseConsistencyDatabases', name, 'enabled')

  value.nil? ? true : value
end

#debug?Boolean



24
25
26
# File 'lib/database_consistency/configuration.rb', line 24

def debug?
  log_level.to_s.match?(/DEBUG/i)
end

#enabled?(*path) ⇒ Boolean



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/database_consistency/configuration.rb', line 37

def enabled?(*path)
  current = configuration

  value = global_enabling

  path.each do |key|
    current = find(key.to_s, current)
    return value unless current.is_a?(Hash)

    next if current['enabled'].nil?

    value = current['enabled']
  end

  value
end

#model_enabled?(model) ⇒ Boolean



54
55
56
# File 'lib/database_consistency/configuration.rb', line 54

def model_enabled?(model)
  database_enabled?(Helper.database_name(model)) && enabled?(model.name.to_s)
end