Module: RSMP::Config

Defined in:
lib/rsmp/config.rb

Overview

Validation helpers for RSMP runtime configuration hashes and files.

Class Method Summary collapse

Class Method Details

.load_file(path, type:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rsmp/config.rb', line 9

def load_file(path, type:)
  raise RSMP::ConfigurationError, 'not found' unless File.exist?(path)
  raise RSMP::ConfigurationError, 'is not a file' unless File.file?(path)
  raise RSMP::ConfigurationError, 'must be a YAML file (.yml or .yaml)' unless yaml_file?(path)

  raw = YAML.load_file(path)
  raise RSMP::ConfigurationError, "Config #{path} must be a hash" unless raw.is_a?(Hash) || raw.nil?

  raw ||= {}
  settings = raw.dup
  log_settings = settings.delete('log') || {}
  validate(settings, type: resolve_type(type, settings), log_settings: log_settings)
rescue Psych::SyntaxError => e
  raise RSMP::ConfigurationError, "Cannot read config file #{path}: #{e}"
end

.typesObject



25
26
27
# File 'lib/rsmp/config.rb', line 25

def types
  %w[site supervisor tlc]
end

.validate(settings = {}, type:, source: nil, log_settings: nil) ⇒ Object



5
6
7
# File 'lib/rsmp/config.rb', line 5

def validate(settings = {}, type:, source: nil, log_settings: nil)
  options_class_for(type).new(settings, source: source, log_settings: log_settings)
end