Module: Sinclair::Configurable
- Defined in:
- lib/sinclair/configurable.rb
Overview
Module capable of giving configuration capability
By extending Configurable, class receives the methods public .config, .reset_config and .configure and the private methods .configurable_with, .configurable_by and .as_options
Constant Summary collapse
- CONFIG_CLASS_WARNING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Deprecation warning message
'Config classes attributes should ' \ 'be defined inside the class or through the usage of ' \ "configurable_with.\n" \ "In future releases this will be enforced.\n" \ 'see more on https://github.com/darthjee/sinclair/blob/master/WARNINGS.md#usage-of-custom-config-classes'
Instance Method Summary collapse
-
#as_options(options_hash = {}) ⇒ Sinclair::Option
Returns options with configurated values.
-
#config ⇒ Config, Object
Returns current instance of config.
-
#configurable_by(config_class, with: []) ⇒ ConfigFactory
Allows configuration to happen through custom config class.
-
#configurable_with(*attributes) ⇒ Array<Symbol>
Adds a configuration option to config class.
-
#configure(config_hash = {}) {|ConfigBuilder| ... } ⇒ Object
Set the values in the config.
-
#reset_config ⇒ NilClass
Cleans the current config instance.
Instance Method Details
#as_options(options_hash = {}) ⇒ Sinclair::Option
Returns options with configurated values
89 |
# File 'lib/sinclair/configurable.rb', line 89 delegate :as_options, to: :config |
#config ⇒ Config, Object
Returns current instance of config
the method returns the same instance until reset_config
is called
|
# File 'lib/sinclair/configurable.rb', line 30
|
#configurable_by(config_class, with: []) ⇒ ConfigFactory
Allows configuration to happen through custom config class
configurable_with does not add methods to config_class. If needed, those can be added by a subsequent call to #configurable_with
201 202 203 204 205 206 207 208 |
# File 'lib/sinclair/configurable.rb', line 201 def configurable_by(config_class, with: []) warn CONFIG_CLASS_WARNING if with.present? @config_factory = ConfigFactory.new( config_class: config_class, config_attributes: with.map(&:to_sym) ) end |
#configurable_with(*attributes) ⇒ Array<Symbol>
Adds a configuration option to config class
152 153 154 |
# File 'lib/sinclair/configurable.rb', line 152 def configurable_with(*attributes) config_factory.add_configs(*attributes) end |
#configure(config_hash = {}) {|ConfigBuilder| ... } ⇒ Object
Set the values in the config
The block given is evaluated by the Sinclair::ConfigBuilder where each method missed will be used to set a variable in the config
79 |
# File 'lib/sinclair/configurable.rb', line 79 delegate :config, :reset_config, :configure, to: :config_factory |
#reset_config ⇒ NilClass
Cleans the current config instance
After cleaning it, #config will generate a new instance
|
# File 'lib/sinclair/configurable.rb', line 46
|