module RemiLib::Config::ConfigFile
Overview
The ConfigFile
module is included in classes that represent a
configuration file. This module must be included for the library to handle
the configuration (de)serialization correctly.
Any class that includes ConfigFile
must also be annotated with
ConfigOpts
to declare the associated configuration filename and format.
For example:
require "libremiliacr"
module SomeProgram
# Define a class to represent a configuration file named "test.json".
@[RemiConf::ConfigOpts(filename: "test.json", format: :json)]
class Config
include ::RemiConf::ConfigFile
property username : String = ""
end
# Define a resolver that will automatically locate config files.
res = RemiConf::Resolver.xdg("some-program")
# Read the config. Since we're using an xdg resolver, this will look for the
# file at $XDG_CONFIG_HOME/some-program/test.json
config = Config.readConfig(res)
puts config.username
end
Defined in:
remilib/config/configfile.crInstance Method Summary
-
#write(io : IO)
Serializes this instance to
io
using the associated format. -
#write(filename : Path)
Serializes this instance using the associated format, then writes the serialized data to
filename
. -
#write(res : Resolver)
Serializes this instance using the associated format, then writes the serialized data to the associated configuration file.
Instance Method Detail
Serializes this instance using the associated format, then writes the
serialized data to filename
. Any existing file will be overwritten.
Serializes this instance using the associated format, then writes the serialized data to the associated configuration file. Any existing file will be overwritten.