class CrConfig::Providers::ProfileFileConfigProvider
Overview
Handles and loads up an entire directory of configuration files
This provider is best used when there is a single "base" configuration file that has all configurations defined, and then other configuration files can be layered on top of that one, providing overrides based on the environment the application runs in.
This provider has lots of configuration switches that can be used when loading files from a directory
# Assume directory `configs` exists and contains `config-base.yaml`, `config-test.yaml`, `config-local.yaml`, and `config-prod.yaml`
CrConfig::Providers::ProfileFileConfigProvirer.new
.folder("configs")
.separator("-")
.base_file("config.yaml")
.profiles do
# Here is where a list of "profiles" of configurations can be provided.
# These can be obtained from anywhere that's appropriate (obviously before
# configuration has completed being read in), such as an environment variable.
["base", "test", "prod"]
end
The above provider, when its #populate
method is called, will read in and load config-base.yaml
, config-test.yaml
, and config-prod.yaml
,
in that order, leaving the production configurations as having the highest precedence. config-local.yaml
won't be read, and a file named
config.yaml
doesn't need to exist.
Defined in:
cr-config/abstract_provider.crInstance Method Summary
-
#base_file(base_file : String)
Base name for the configuration files
-
#folder(folder_path : String)
Base folder path to read config files from, relative from where the server is running from
-
#populate(builder : AbstractBuilder)
Will read in and and load files, used the
SimpleFileProvider
to perform the actual file reading, configuration files under"#{@filder_path}/#{file_name}"
, for every file name constructed from the@base_file
and list of#profiles
provided. -
#profiles(&block : -> Array(String))
Block to be run when determining which "profiles" to load
-
#separator(profile_separator : String)
Seperator to use when constructing the different profile versions of the config file.
Instance methods inherited from class CrConfig::Providers::AbstractProvider
populate(builder : AbstractBuilder)
populate
Instance Method Detail
Base folder path to read config files from, relative from where the server is running from
Will read in and and load files, used the SimpleFileProvider
to perform the actual file reading, configuration files under
"#{@filder_path}/#{file_name}"
, for every file name constructed from the @base_file
and list of #profiles
provided.
Given base file name config.json
, a list of profiles ["prof1"]
, and separator of _
, this will attempt to load all files
in ["config_prof1.json"]
under the provided folder_path. The profiles and separator are inserted where the file extension is found in the base file name.