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

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

Parameters:

  • path (String)

    the filesystem path to the file to be read

  • required (Boolean) (defaults to: false)

    whether the file is required to exist, defaults

Returns:

  • (String, nil)

    the content of the file if it exists, or nil if it

Raises:



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