class RemiLib::Config::Resolver
- RemiLib::Config::Resolver
- Reference
- Object
Overview
The Resolver class is used to locate configuration files and user-specific
data files in a platform-agnostic way.
Defined in:
remilib/config/resolver.crClass Method Summary
-
.custom(baseName : String, configDir : String | Path, dataDir : String | Path, *, dontCreateMissingDirs : Bool = false)
Creates a new
Resolverthat uses custom directories. -
.windows(baseName : String, *, dontCreateMissingDirs : Bool = false)
Creates a new
Resolverthat understands Windows%APPDATA%. -
.xdg(baseName : String, *, dontCreateMissingDirs : Bool = false)
Creates a new
Resolverthat understands the XDG Base Directory Specification.
Instance Method Summary
-
#baseName : String
The directory name to use when storing configuration or data files.
-
#configDir : Path
The associated data directory.
-
#dataDir : Path
The associated data directory.
-
#dataFile(symname : Symbol) : Path
Given a symbolic name for a data file, return the
Pathassociated with it. -
#dataFile(symname : Symbol, &) : Nil
Looks up the associated
Pathfor a symbolic name for a data file, then opens the file usingFile.openand yields the stream. -
#dataFile?(symname : Symbol) : Path | Nil
Given a symbolic name for a data file, return the
Pathassociated with it. -
#dataFile?(symname : Symbol, &) : Bool
Looks up the associated
Pathfor a symbolic name for a data file, then checks to see if the file exists. -
#defineDataFile(symname : Symbol, filename : String | Path)
Registers a new data file with this
Resolversuch that a filename becomes associated with aSymbol. -
#defineDataFile!(symname : Symbol, filename : String | Path)
Registers a new data file with this
Resolversuch that a filename becomes associated with aSymbol. -
#recreateMissing
Creates the
#configDirand/or#dataDirif either are missing. -
#type : DirectoryType
The associated type of configuration directory.
Class Method Detail
Creates a new Resolver that uses custom directories. When this is used,
the #configDir and #dataDir are not generated based on the
#baseName, and are instead the literal values passed into this method.
If dontCreateMissingDirs is true, then the #configDir and #dataDir
are not created automatically.
Creates a new Resolver that understands Windows %APPDATA%. If
dontCreateMissingDirs is true, then the #configDir and #dataDir
are not created automatically.
Creates a new Resolver that understands the XDG Base Directory
Specification.
If dontCreateMissingDirs is true, then the #configDir and #dataDir
are not created automatically.
Instance Method Detail
The directory name to use when storing configuration or data files. For
example, if the #type is DirectoryType::Xdg, and the #baseName is
equal to "test-program", then this Resolver will put configuration files
under $XDG_CONFIG_HOME/test-program/ and data files under
$XDG_DATA_HOME/some-program/.
The associated data directory. This is determined automatically based on
the #baseName. For example, if the #type is DirectoryType::Xdg, and
the #baseName is equal to "test-program", then this Resolver will put
configuration files under $XDG_CONFIG_HOME/test-program/.
The associated data directory. This is determined automatically based on
the #baseName. For example, if the #type is DirectoryType::Xdg, and
the #baseName is equal to "test-program", then this Resolver will put
data files under $XDG_DATA_HOME/some-program/.
Given a symbolic name for a data file, return the Path associated with
it. If the symbol is not registered with this Resolver, then this
raises an UnknownDataFileError.
Looks up the associated Path for a symbolic name for a data file, then
opens the file using File.open and yields the stream. If the symbol is
not registered with this Resolver, then this raises an
UnknownDataFileError.
Given a symbolic name for a data file, return the Path associated with
it. If the symbol is not registered with this Resolver, this returns
nil.
Looks up the associated Path for a symbolic name for a data file, then
checks to see if the file exists. If it does, this opens the file using
File.open and yields the stream, then returns true. Otherwise this
returns false.
If the symbol is not registered with this Resolver, then this returns
false.
Registers a new data file with this Resolver such that a filename
becomes associated with a Symbol. This symbol can later be used to
reference that file.
The symbol must be unique to this Resolver instance.
Registers a new data file with this Resolver such that a filename
becomes associated with a Symbol. This symbol can later be used to
reference that file.
If the symbol is not unique to this Resolver instance, then the old path
is forgotten and the symbol becomes associated with the new path.