Class: Sinclair::ConfigFactory Private
- Inherits:
-
Object
- Object
- Sinclair::ConfigFactory
- Defined in:
- lib/sinclair/config_factory.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class responsible for configuring the configuration class
Instance Method Summary collapse
-
#add_configs(*attributes) ⇒ Array<Symbol>
private
Adds possible configurations.
-
#child ⇒ ConfigFactory
private
Returns a new instance of ConfigFactory.
-
#config ⇒ Config, Object
private
Returns current instance of config.
-
#configure {|ConfigBuilder| ... } ⇒ Object
private
Set the values in the config.
-
#initialize(config_class: Class.new(Config), config_attributes: []) ⇒ ConfigFactory
constructor
private
A new instance of ConfigFactory.
-
#reset_config ⇒ NilClass
private
Cleans the current config instance.
Constructor Details
#initialize(config_class: Class.new(Config), config_attributes: []) ⇒ ConfigFactory
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ConfigFactory.
21 22 23 24 |
# File 'lib/sinclair/config_factory.rb', line 21 def initialize(config_class: Class.new(Config), config_attributes: []) @config_class = config_class @config_attributes = config_attributes.dup end |
Instance Method Details
#add_configs(*attributes) ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds possible configurations
It change the configuration class adding methods and keeps track of those configurations so that Sinclair::ConfigBuilder is able to set those values when invoked
80 81 82 83 |
# File 'lib/sinclair/config_factory.rb', line 80 def add_configs(*attributes) config_class.attr_reader(*attributes) config_attributes.concat(attributes.map(&:to_sym)) end |
#child ⇒ ConfigFactory
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ConfigFactory
the new instance will have the same config_attributes and for config_class a child of the current config_class
This method is called when initializing Sinclair::Configurable config_factory and the superclass is also configurable
This way, child classes from other Sinclair::Configurable classes will have a config_class that is a child from the original config_class
130 131 132 133 134 135 |
# File 'lib/sinclair/config_factory.rb', line 130 def child self.class.new( config_class: Class.new(config_class), config_attributes: config_attributes ) end |
#config ⇒ Config, Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns current instance of config
the method returns the same instance until reset_config
is called
38 39 40 |
# File 'lib/sinclair/config_factory.rb', line 38 def config @config ||= config_class.new end |
#configure {|ConfigBuilder| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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
112 113 114 |
# File 'lib/sinclair/config_factory.rb', line 112 def configure(&block) config_builder.instance_eval(&block) end |
#reset_config ⇒ NilClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Cleans the current config instance
After cleaning it, #config will generate a new instance
57 58 59 |
# File 'lib/sinclair/config_factory.rb', line 57 def reset_config @config = nil end |