module Scar::Config
Overview
This module aims to be a simple interface for storing basic key-value configuration like keybindings, window settings, ..
You can store everything that can be represented by YAML::Any
.
Example usage:
# At toplevel
Scar::Config.set_defaults({
int: 7331,
str: "hello world",
arr: [1, 3, 3, 7],
})
puts Config[:int] # => 7331
Scar::Config[:str] = "lol"
puts Config[:str] # => lol
Scar::Util.dir = "config-examle" # don't forget to specify a data directory for your files!
Scar::Config.save # using default filename "config.yml"
Scar::Config.reset(:str)
puts Config[:str] # => hello world
# By loading the saved config from before, the `:str` entry is "lol" again
Scar::Config.load "config.yml"
puts Scar::Config[:str] # => lol
Extended Modules
Defined in:
scar/config.crInstance Method Summary
-
#[](key) : YAML::Type
Returns the value for the given configuration entry
-
#[]=(key, value)
Sets a given configuration entry to a new value
-
#dump
Returns the yaml dump of the configuration data
-
#load(fname : String = "config.yml")
Loads configuration values from the given file (using
Util#read_file
) -
#load_defaults
Resets all configuration entries to their standard value
-
#reset(key)
Resets the value of a configuration entry to it's standard (see
Config#define_defaults
) -
#save(fname : String = "config.yml")
Saves the configuration to a file with given file name (using
Util#write_file
)
Macro Summary
-
set_defaults(defaults)
Defines standard values for configuration entries to fall back to.
Instance Method Detail
Returns the value for the given configuration entry
You can pass strings or symbols to this method. Returns the standard value if the configuration entry is not set.
Loads configuration values from the given file (using Util#read_file
)
Resets the value of a configuration entry to it's standard (see Config#define_defaults
)
Saves the configuration to a file with given file name (using Util#write_file
)
Macro Detail
Defines standard values for configuration entries to fall back to.
Specify the defaults as a NamedTuple
of format {entry name}: {value}
.
Example:
Scar::Config.define_defaults({
str: "hello world",
arr: [1, 3, 3, 7],
})