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

Returns a new instance of Configuration.



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

def initialize(file_paths = DEFAULT_PATH)
  @configuration = existing_configurations(file_paths).then do |existing_paths|
    if existing_paths.any?
      puts "Loaded configurations: #{existing_paths.join(', ')}"
    else
      puts 'No configurations were provided'
    end
    extract_configurations(existing_paths)
  end

  load_custom_checkers
end

Instance Method Details

#colored?Boolean

Returns:

  • (Boolean)


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

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

#database_enabled?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

  value.nil? ? true : value
end

#debug?Boolean

Returns:

  • (Boolean)


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

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

#enabled?(*path) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Returns:

  • (Boolean)


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

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