Module: Evilution::Config::FileLoader Private
- Defined in:
- lib/evilution/config/file_loader.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- KNOWN_KEYS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Keys recognised in YAML config files.
target_filesis intentionally excluded because it is CLI-positional (the file paths afterevilution run). (Evilution::Config::DEFAULTS.keys + %i[hooks]).uniq.freeze
Class Method Summary collapse
- .load ⇒ Object private
- .validate_known_keys!(keys, path:) ⇒ Object private
- .validate_schema!(data, path:) ⇒ Object private
- .validate_schema_version_value!(version, path:) ⇒ Object private
Class Method Details
.load ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/evilution/config/file_loader.rb', line 12 def load Evilution::Config::CONFIG_FILES.each do |path| next unless File.exist?(path) data = YAML.safe_load_file(path, symbolize_names: true) return {} unless data.is_a?(Hash) validate_schema!(data, path: path) if data.key?(:schema_version) return data rescue Psych::SyntaxError, Psych::DisallowedClass => e raise Evilution::ConfigError.new("failed to parse config file #{path}: #{e.}", file: path) rescue SystemCallError => e raise Evilution::ConfigError.new("cannot read config file #{path}: #{e.}", file: path) end {} end |
.validate_known_keys!(keys, path:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 55 56 57 58 59 60 |
# File 'lib/evilution/config/file_loader.rb', line 52 def validate_known_keys!(keys, path:) unknown = keys - KNOWN_KEYS return if unknown.empty? raise Evilution::ConfigError.new( "unknown key(s) #{unknown.inspect} in #{path}. Known keys: #{KNOWN_KEYS.sort.inspect}", file: path ) end |
.validate_schema!(data, path:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 |
# File 'lib/evilution/config/file_loader.rb', line 30 def validate_schema!(data, path:) validate_schema_version_value!(data[:schema_version], path: path) validate_known_keys!(data.keys, path: path) end |
.validate_schema_version_value!(version, path:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/evilution/config/file_loader.rb', line 35 def validate_schema_version_value!(version, path:) unless version.is_a?(Integer) && version.positive? raise Evilution::ConfigError.new( "invalid schema_version #{version.inspect} in #{path}: must be a positive Integer", file: path ) end return if version <= Evilution::Config::CURRENT_SCHEMA_VERSION raise Evilution::ConfigError.new( "schema_version #{version} in #{path} is newer than this evilution gem supports " \ "(current: #{Evilution::Config::CURRENT_SCHEMA_VERSION}). Upgrade the gem.", file: path ) end |