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(filepaths = DEFAULT_PATH) ⇒ Configuration

Returns a new instance of Configuration.



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

def initialize(filepaths = DEFAULT_PATH)
  @configuration = Array(filepaths).each_with_object({}) do |filepath, result|
    content =
      if filepath && File.exist?(filepath)
        data = load_yaml_config_file(filepath)
        data.is_a?(Hash) ? data : {}
      else
        {}
      end

    combine_configs!(result, content)
  end
end

Instance Method Details

#colored?Boolean

Returns:

  • (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

#debug?Boolean

Returns:

  • (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

Returns:

  • (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 = current[key.to_s]
    return value unless current.is_a?(Hash)

    next if current['enabled'].nil?

    value = current['enabled']
  end

  value
end