MywayConfig::Base¶
Base class for configuration. Extends Anyway::Config.
Class Methods¶
config_name¶
Set the configuration name.
Parameters:
name(Symbol) - The configuration name
Used for:
- Finding config files (
config/myapp.yml) - XDG config path (
~/.config/myapp/config.yml) - Loader registration
env_prefix¶
Set the environment variable prefix.
Parameters:
prefix(Symbol) - The prefix for environment variables
Result:
Environment variables like MYAPP_DATABASE__HOST will be recognized.
defaults_path¶
Register the defaults file path.
Parameters:
path(String) - Absolute path to the defaults YAML file
Raises:
ConfigurationErrorif the file does not exist
auto_configure!¶
Auto-generate attributes and coercions from the YAML schema.
Raises:
ConfigurationErrorifdefaults_pathis not set
Behavior:
- Creates
attr_configfor each key in thedefaults:section - Coerces Hash values to
ConfigSection - Coerces Symbol values to symbols
schema¶
Returns the defaults section from the YAML file.
Returns:
Hash- The parseddefaults:section
config_section_coercion¶
Create a coercion proc that merges with schema defaults.
Parameters:
section_key(Symbol) - The section key in the schema
Returns:
Proc- Coercion proc for use withcoerce_types
config_section¶
Create a simple ConfigSection coercion (without schema defaults).
Returns:
Proc- Coercion proc
to_symbol¶
Create a symbol coercion proc.
Returns:
Proc- Coercion proc that converts to symbol
env¶
Get the current environment.
Returns:
String- Current environment name
Priority:
Anyway::Settings.current_environmentENV['RAILS_ENV']ENV['RACK_ENV']'development'
valid_environments¶
Get list of valid environment names from the defaults file.
Returns:
Array<Symbol>- Environment names defined in YAML
valid_environment?¶
Check if current environment is valid.
Returns:
Boolean- true if environment has a section in YAML
Instance Methods¶
initialize¶
Create a new configuration instance.
# Default (use loaders)
config = MyConfig.new
# From file path
config = MyConfig.new("/path/to/config.yml")
# From Hash
config = MyConfig.new(database: { host: "custom" })
Parameters:
source(nil, String, Pathname, Hash) - Configuration source
Raises:
ConfigurationErrorif file path doesn't existConfigurationErrorif source type is invalid
environment¶
Get the current environment name.
Returns:
String- Current environment
development?¶
Check if running in development environment.
production?¶
Check if running in production environment.
test?¶
Check if running in test environment.
valid_environment?¶
Check if current environment is valid.