Class: DatabaseConsistency::Configuration
- Inherits:
-
Object
- Object
- DatabaseConsistency::Configuration
- 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
- #colored? ⇒ Boolean
- #database_enabled?(name) ⇒ Boolean
- #debug? ⇒ Boolean
- #enabled?(*path) ⇒ Boolean
-
#initialize(file_paths = DEFAULT_PATH) ⇒ Configuration
constructor
A new instance of Configuration.
- #model_enabled?(model) ⇒ Boolean
Constructor Details
#initialize(file_paths = DEFAULT_PATH) ⇒ Configuration
Returns a new instance of Configuration.
10 11 12 13 14 15 16 17 18 19 |
# 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 end |
Instance Method Details
#colored? ⇒ Boolean
25 26 27 28 29 30 31 |
# File 'lib/database_consistency/configuration.rb', line 25 def colored? if ENV.key?('COLOR') ENV['COLOR'].match?(/1|true|yes/) else settings && settings['color'] end end |
#database_enabled?(name) ⇒ Boolean
55 56 57 58 59 |
# File 'lib/database_consistency/configuration.rb', line 55 def database_enabled?(name) value = configuration.dig('DatabaseConsistencyDatabases', name, 'enabled') value.nil? ? true : value end |
#debug? ⇒ Boolean
21 22 23 |
# File 'lib/database_consistency/configuration.rb', line 21 def debug? log_level.to_s.match?(/DEBUG/i) end |
#enabled?(*path) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/database_consistency/configuration.rb', line 34 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
51 52 53 |
# File 'lib/database_consistency/configuration.rb', line 51 def model_enabled?(model) database_enabled?(Helper.database_name(model)) && enabled?(model.name.to_s) end |