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

CONFIGURATION_PATH =
'.database_consistency.yml'

Instance Method Summary collapse

Constructor Details

#initialize(filepath = CONFIGURATION_PATH) ⇒ Configuration

Returns a new instance of Configuration.



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

def initialize(filepath = CONFIGURATION_PATH)
  @configuration = if filepath && File.exist?(filepath)
                     data = YAML.load_file(filepath)
                     data.is_a?(Hash) ? data : {}
                   else
                     {}
                   end
end

Instance Method Details

#enabled?(*path) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/database_consistency/configuration.rb', line 20

def enabled?(*path)
  current = configuration

  path.each do |key|
    current = current[key.to_s]
    return true unless current.is_a?(Hash)

    next if current['enabled'].nil?

    return false unless current['enabled']
  end

  true
end