Class: ShinseiConfig::RootConfig
- Inherits:
-
Object
- Object
- ShinseiConfig::RootConfig
- Defined in:
- lib/shinsei_config/root_config.rb
Overview
Base class for configuration. Users inherit from this class.
Class Method Summary collapse
-
.config ⇒ Object
Access config instance.
-
.load! ⇒ Object
Load and validate configuration.
-
.method_missing(method_name) ⇒ Object
Delegate method calls to config instance.
-
.reload! ⇒ Object
Reload configuration.
- .respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
.schema(&block) ⇒ Object
Define validation schema.
-
.settings(&block) ⇒ Object
Configure settings for this config class.
Class Method Details
.config ⇒ Object
Access config instance
57 58 59 60 61 |
# File 'lib/shinsei_config/root_config.rb', line 57 def config raise Error, "Config not loaded. Call #{name}.load! first" unless @config @config end |
.load! ⇒ Object
Load and validate configuration
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/shinsei_config/root_config.rb', line 28 def load! validate_setup! # Load YAML with ERB and env splitting loader = Loader.new( config_path: settings.config_path, env: settings.env, **settings.yaml_opts ) config_hash = loader.load # Validate against schema if defined schema&.validate!(config_hash) # Build config object @config = ConfigBuilder.build(config_hash) self end |
.method_missing(method_name) ⇒ Object
Delegate method calls to config instance
65 66 67 68 69 70 71 |
# File 'lib/shinsei_config/root_config.rb', line 65 def method_missing(method_name, *, &) if config.respond_to?(method_name) config.public_send(method_name, *, &) else super end end |
.reload! ⇒ Object
Reload configuration
50 51 52 53 |
# File 'lib/shinsei_config/root_config.rb', line 50 def reload! @config = nil load! end |
.respond_to_missing?(method_name, include_private = false) ⇒ Boolean
74 75 76 |
# File 'lib/shinsei_config/root_config.rb', line 74 def respond_to_missing?(method_name, include_private = false) config.respond_to?(method_name) || super end |
.schema(&block) ⇒ Object
Define validation schema
21 22 23 24 |
# File 'lib/shinsei_config/root_config.rb', line 21 def schema(&block) @schema_validator = SchemaValidator.new(&block) if block @schema_validator end |
.settings(&block) ⇒ Object
Configure settings for this config class
13 14 15 16 17 |
# File 'lib/shinsei_config/root_config.rb', line 13 def settings(&block) @settings ||= Settings.new block&.call(@settings) @settings end |