Module: ConstConf::FilePlugin
- Included in:
- EnvDirExtension
- Defined in:
- lib/const_conf/file_plugin.rb
Overview
A module that provides functionality for reading file contents as configuration values.
The FilePlugin module extends the ConstConf::Setting class to enable configuration settings that are sourced from file contents rather than environment variables. This allows for more complex configuration data, such as SSL certificates or API keys, to be loaded from files and used within the application’s configuration system.
Instance Method Summary collapse
-
#file(path, required: false) ⇒ String?
Reads the content of a file and returns it as a string.
Instance Method Details
#file(path, required: false) ⇒ String?
Reads the content of a file and returns it as a string.
This method attempts to read the contents of a file specified by the given path. If the file exists, its content is returned as a string. If the file does not exist and the required flag is set to true, a RequiredValueNotConfigured exception is raised.
to false
doesn’t and required is false
and required is true
26 27 28 29 30 31 32 33 |
# File 'lib/const_conf/file_plugin.rb', line 26 def file(path, required: false) if File.exist?(path) File.read(path) elsif required raise ConstConf::RequiredValueNotConfigured, "file required at path #{path.to_s.inspect}" end end |