Class: Mammoth::Configuration
- Inherits:
-
Object
- Object
- Mammoth::Configuration
- Defined in:
- lib/mammoth/configuration.rb
Overview
Loads and validates Mammoth configuration.
Configuration is intentionally schema-backed so the same contract can power editor IntelliSense, preflight validation, and runtime startup checks.
Defined Under Namespace
Modules: Providers
Constant Summary collapse
- DEFAULT_SCHEMA_PATH =
Default JSON Schema used to validate Mammoth YAML configuration files.
File.("../../config/mammoth.schema.json", __dir__.to_s)
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#schema_path ⇒ Object
readonly
Returns the value of attribute schema_path.
Class Method Summary collapse
-
.from_hash(data, path: nil, schema_path: DEFAULT_SCHEMA_PATH) ⇒ Mammoth::Configuration
Build and validate a configuration from an in-memory Hash.
-
.load(path, schema_path: DEFAULT_SCHEMA_PATH) ⇒ Mammoth::Configuration
Load and validate a configuration file.
Instance Method Summary collapse
-
#dig(*keys) ⇒ Object?
Fetch a nested value from the loaded configuration.
-
#initialize(path, schema_path: DEFAULT_SCHEMA_PATH, data: nil) ⇒ Configuration
constructor
A new instance of Configuration.
-
#load ⇒ Mammoth::Configuration
Load and validate the configuration file.
Constructor Details
#initialize(path, schema_path: DEFAULT_SCHEMA_PATH, data: nil) ⇒ Configuration
Returns a new instance of Configuration.
42 43 44 45 46 |
# File 'lib/mammoth/configuration.rb', line 42 def initialize(path, schema_path: DEFAULT_SCHEMA_PATH, data: nil) @path = path @schema_path = schema_path @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
16 17 18 |
# File 'lib/mammoth/configuration.rb', line 16 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/mammoth/configuration.rb', line 16 def path @path end |
#schema_path ⇒ Object (readonly)
Returns the value of attribute schema_path.
16 17 18 |
# File 'lib/mammoth/configuration.rb', line 16 def schema_path @schema_path end |
Class Method Details
.from_hash(data, path: nil, schema_path: DEFAULT_SCHEMA_PATH) ⇒ Mammoth::Configuration
Build and validate a configuration from an in-memory Hash.
35 36 37 |
# File 'lib/mammoth/configuration.rb', line 35 def self.from_hash(data, path: nil, schema_path: DEFAULT_SCHEMA_PATH) Providers::HashProvider.new(data, path: path).load(schema_path: schema_path) end |
.load(path, schema_path: DEFAULT_SCHEMA_PATH) ⇒ Mammoth::Configuration
Load and validate a configuration file.
24 25 26 |
# File 'lib/mammoth/configuration.rb', line 24 def self.load(path, schema_path: DEFAULT_SCHEMA_PATH) Providers::FileProvider.new(path).load(schema_path: schema_path) end |
Instance Method Details
#dig(*keys) ⇒ Object?
Fetch a nested value from the loaded configuration.
67 68 69 |
# File 'lib/mammoth/configuration.rb', line 67 def dig(*keys) data&.dig(*keys) end |
#load ⇒ Mammoth::Configuration
Load and validate the configuration file.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mammoth/configuration.rb', line 52 def load @data ||= load_yaml_file raise ConfigurationError, "configuration must be a YAML mapping" unless data.is_a?(Hash) validate_schema! validate_destination_names! self rescue Psych::SyntaxError => e raise ConfigurationError, "invalid YAML in #{path}: #{e.}" end |