Class: ConfigX::ConfigFactory
- Inherits:
-
Object
- Object
- ConfigX::ConfigFactory
- Defined in:
- lib/config_x/config_factory.rb
Overview
This class is responsible for loading configuration settings for an application. It follows a specific order in loading these settings:
1. Reads default config
2. Reads all the config files provided in the order
3. Reads environment variables
Class Method Summary collapse
-
.default_config_class ⇒ Class<ConfigX::Configurable>
Default configuration class.
-
.default_config_root ⇒ Object
Default root directory for configuration.
-
.default_dir_name ⇒ Object
Default directory name for environment-specific settings.
-
.default_env ⇒ Object
Default environment name.
-
.default_env_prefix ⇒ Object
Default environment variable prefix.
-
.default_env_separator ⇒ Object
Default environment variable separator.
-
.default_file_name ⇒ Object
Default config file name.
-
.load ⇒ Object
Load method to initialize and load the configuration.
Instance Method Summary collapse
-
#initialize(env = self.class.default_env, env_prefix: self.class.default_env_prefix, env_separator: self.class.default_env_separator, dir_name: self.class.default_dir_name, file_name: self.class.default_file_name, config_root: self.class.default_config_root, config_class: self.class.default_config_class) ⇒ ConfigFactory
constructor
Initializes a new instance of the ConfigFactory class.
-
#load(*additional_sources) ⇒ UntypedConfig
Loads the configuration from the sources and additional sources.
Constructor Details
#initialize(env = self.class.default_env, env_prefix: self.class.default_env_prefix, env_separator: self.class.default_env_separator, dir_name: self.class.default_dir_name, file_name: self.class.default_file_name, config_root: self.class.default_config_root, config_class: self.class.default_config_class) ⇒ ConfigFactory
Initializes a new instance of the ConfigFactory class.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/config_x/config_factory.rb', line 44 def initialize( env = self.class.default_env, env_prefix: self.class.default_env_prefix, env_separator: self.class.default_env_separator, dir_name: self.class.default_dir_name, file_name: self.class.default_file_name, config_root: self.class.default_config_root, config_class: self.class.default_config_class ) @env = env @env_prefix = env_prefix @env_separator = env_separator @dir_name = dir_name @file_name = file_name @config_root = config_root @config_class = config_class end |
Class Method Details
.default_config_class ⇒ Class<ConfigX::Configurable>
Default configuration class
31 |
# File 'lib/config_x/config_factory.rb', line 31 def default_config_class = UntypedConfig |
.default_config_root ⇒ Object
Default root directory for configuration
27 |
# File 'lib/config_x/config_factory.rb', line 27 def default_config_root = "config" |
.default_dir_name ⇒ Object
Default directory name for environment-specific settings
18 |
# File 'lib/config_x/config_factory.rb', line 18 def default_dir_name = "settings" |
.default_env ⇒ Object
Default environment name
21 |
# File 'lib/config_x/config_factory.rb', line 21 def default_env = "production" |
.default_env_prefix ⇒ Object
Default environment variable prefix
12 |
# File 'lib/config_x/config_factory.rb', line 12 def default_env_prefix = "SETTINGS" |
.default_env_separator ⇒ Object
Default environment variable separator
15 |
# File 'lib/config_x/config_factory.rb', line 15 def default_env_separator = "__" |
.default_file_name ⇒ Object
Default config file name
24 |
# File 'lib/config_x/config_factory.rb', line 24 def default_file_name = "settings" |
.load ⇒ Object
Load method to initialize and load the configuration
34 |
# File 'lib/config_x/config_factory.rb', line 34 def load(...) = new(...).load |
Instance Method Details
#load(*additional_sources) ⇒ UntypedConfig
Loads the configuration from the sources and additional sources.
65 66 67 68 69 |
# File 'lib/config_x/config_factory.rb', line 65 def load(*additional_sources) (sources + additional_sources) .reduce(Builder.new) { |builder, source| builder.add_source(source) } .load(config_class:) end |