Class: FeduxOrgStdlib::FileFinder
- Inherits:
-
Object
- Object
- FeduxOrgStdlib::FileFinder
- Defined in:
- lib/fedux_org_stdlib/file_finder.rb,
lib/fedux_org_stdlib/file_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_file>.yaml
-
$HOME/.<application_name>/<config_file>.yaml
-
$HOME/.<config_file>.yaml
-
$HOME/.<config_file>rc
-
/etc/.<application_name>/<config_file>.yaml
Please keep in mind
-
application_name: Module of your class, e.g. “MyApplication” becomes “my_application”
-
config_file: Pluarized name of your class and “File” strip off, e.g “ClientFile” becomes “client.yaml”
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_file
-
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_file_paths
Below you find some examples for the usage of the class:
Defined Under Namespace
Modules: Exceptions
Instance Attribute Summary collapse
-
#file ⇒ FileFinder
readonly
Create a new instance of config.
-
#logger ⇒ FileFinder
readonly
Create a new instance of config.
-
#working_directory ⇒ FileFinder
readonly
Create a new instance of config.
Instance Method Summary collapse
-
#initialize(file: nil, working_directory: Dir.getwd, logger: FeduxOrgStdlib::Logging::Logger.new) ⇒ FileFinder
constructor
A new instance of FileFinder.
-
#preferred_configuration_file ⇒ String
Return the path to the preferred configuration file.
Constructor Details
#initialize(file: nil, working_directory: Dir.getwd, logger: FeduxOrgStdlib::Logging::Logger.new) ⇒ FileFinder
Returns a new instance of FileFinder.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fedux_org_stdlib/file_finder.rb', line 66 def initialize( file: nil, working_directory: Dir.getwd, logger: FeduxOrgStdlib::Logging::Logger.new ) @logger = logger @working_directory = working_directory @file ||= (file || _available_config_file) logger.debug "None of this files exist #{_allowed_config_file_paths.to_list}." unless file end |
Instance Attribute Details
#file ⇒ FileFinder (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
64 65 66 |
# File 'lib/fedux_org_stdlib/file_finder.rb', line 64 def file @file end |
#logger ⇒ FileFinder (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
64 65 66 |
# File 'lib/fedux_org_stdlib/file_finder.rb', line 64 def logger @logger end |
#working_directory ⇒ FileFinder (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
64 65 66 |
# File 'lib/fedux_org_stdlib/file_finder.rb', line 64 def working_directory @working_directory end |
Instance Method Details
#preferred_configuration_file ⇒ String
Return the path to the preferred configuration file
81 82 83 |
# File 'lib/fedux_org_stdlib/file_finder.rb', line 81 def preferred_configuration_file _allowed_config_file_paths.first end |