Class: ComplexConfig::Config
- Defined in:
- lib/complex_config/config.rb
Overview
Configuration class for setting up ComplexConfig behavior
This class provides a structured way to configure the ComplexConfig system, including environment settings, deep freezing behavior, and plugin registration.
Instance Attribute Summary collapse
-
#config_dir ⇒ Object
Returns the value of attribute config_dir.
-
#deep_freeze ⇒ Object
Returns the value of attribute deep_freeze.
-
#env ⇒ Object
Returns the value of attribute env.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
Instance Method Summary collapse
-
#add_plugin(code) ⇒ self
Adds a plugin to the configuration.
-
#configure(provider) ⇒ self
Applies the configuration to a provider.
-
#initialize ⇒ Config
constructor
Initializes a new configuration instance.
Constructor Details
#initialize ⇒ Config
Initializes a new configuration instance
25 26 27 28 |
# File 'lib/complex_config/config.rb', line 25 def initialize(*) super self.plugins = [] end |
Instance Attribute Details
#config_dir ⇒ Object
Returns the value of attribute config_dir
23 24 25 |
# File 'lib/complex_config/config.rb', line 23 def config_dir @config_dir end |
#deep_freeze ⇒ Object
Returns the value of attribute deep_freeze
23 24 25 |
# File 'lib/complex_config/config.rb', line 23 def deep_freeze @deep_freeze end |
#env ⇒ Object
Returns the value of attribute env
23 24 25 |
# File 'lib/complex_config/config.rb', line 23 def env @env end |
#plugins ⇒ Object
Returns the value of attribute plugins
23 24 25 |
# File 'lib/complex_config/config.rb', line 23 def plugins @plugins end |
Instance Method Details
#add_plugin(code) ⇒ self
Adds a plugin to the configuration
Plugins are lambda expressions that can provide custom behavior for configuration attributes.
56 57 58 59 |
# File 'lib/complex_config/config.rb', line 56 def add_plugin(code) plugins << code self end |
#configure(provider) ⇒ self
Applies the configuration to a provider
This method sets all configuration attributes on the provider and registers any plugins. It’s called internally by ComplexConfig.configure.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/complex_config/config.rb', line 37 def configure(provider) each_pair do |name, value| value.nil? and next name == :plugins and next provider.__send__("#{name}=", value) end plugins.each do |code| provider.add_plugin(code) end self end |