Class: FeduxOrgStdlib::DirectoryFinder
- Inherits:
-
Object
- Object
- FeduxOrgStdlib::DirectoryFinder
- Defined in:
- lib/fedux_org_stdlib/directory_finder.rb,
lib/fedux_org_stdlib/directory_finder/exceptions.rb
Overview
This class detects the file name for an config file. By default it will look for a suitable config file in the given order:
-
$HOME/.config/<application_name>/<config_directory>
-
$HOME/.<application_name>/<config_directory>
-
$HOME/.<config_directory>
-
/etc/.<application_name>/<config_directory>
Please keep in mind
-
application_name: Module of your class, e.g. “MyApplication” becomes “my_application”
-
config_directory: Name of your class and “Directory” strip off, e.g “ClientDirectory” becomes “client”
Most conventions defined by me are implemented as separate methods. If one convention is not suitable for your use case, just overwrite the method.
If you prefer to use a different path to the config file or name of the config file one of the following methods needs to be overwritten:
-
config_directory
-
config_name
-
application_name
If you want the class to look for your config file at a different place overwrite the following method
-
allowed_config_directory_paths
Below you find some examples for the usage of the class:
Defined Under Namespace
Modules: Exceptions
Instance Attribute Summary collapse
-
#directory ⇒ DirectoryFinder
readonly
Create a new instance of config.
-
#logger ⇒ DirectoryFinder
readonly
Create a new instance of config.
Instance Method Summary collapse
-
#initialize(logger: FeduxOrgStdlib::Logging::Logger.new, directory: _available_config_directory) ⇒ DirectoryFinder
constructor
A new instance of DirectoryFinder.
-
#preferred_configuration_directory ⇒ String
Return the path to the preferred configuration file.
Constructor Details
#initialize(logger: FeduxOrgStdlib::Logging::Logger.new, directory: _available_config_directory) ⇒ DirectoryFinder
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fedux_org_stdlib/directory_finder.rb', line 65 def initialize( logger: FeduxOrgStdlib::Logging::Logger.new, directory: _available_config_directory ) @logger = logger @directory = directory unless directory logger.debug "No configuration directory found at #{_allowed_config_directory_paths.to_list}, therefor I'm going to use an empty config object instead." end end |
Instance Attribute Details
#directory ⇒ DirectoryFinder (readonly)
Create a new instance of config
It tries to find a suitable configuration file. If it doesn’t find one the config is empty and uses the defaults defined within a config class
63 64 65 |
# File 'lib/fedux_org_stdlib/directory_finder.rb', line 63 def directory @directory end |
#logger ⇒ DirectoryFinder (readonly)
Create a new instance of config
It tries to find a suitable configuration file. If it doesn’t find one the config is empty and uses the defaults defined within a config class
63 64 65 |
# File 'lib/fedux_org_stdlib/directory_finder.rb', line 63 def logger @logger end |
Instance Method Details
#preferred_configuration_directory ⇒ String
Return the path to the preferred configuration file
80 81 82 |
# File 'lib/fedux_org_stdlib/directory_finder.rb', line 80 def preferred_configuration_directory _allowed_config_directory_paths.first end |