Module: Sinclair::ConfigClass
- Included in:
- Config
- Defined in:
- lib/sinclair/config_class.rb
Overview
Module with all class methods for Config
Any class that will be used as configuration class should extend ConfigClass as #config_attributes is used to check what configurations have been added
Instance Method Summary collapse
-
#add_configs(*names, default) ⇒ MethodsBuilder
Add a config attribute.
-
#config_attributes(*attributes) ⇒ Array<Symbol>
private
Adds an attribute to the list of attributes.
-
#options_class ⇒ Class<Sinclair::Options>
private
Returns the options class exclusive to this configurable.
Instance Method Details
#add_configs(*names, default) ⇒ MethodsBuilder
Add a config attribute
This method adds an attribute (see #config_attributes) and the method readers
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sinclair/config_class.rb', line 82 def add_configs(*args) Config::MethodsBuilder.new(self, *args).tap do |builder| builder.build Sinclair::InputHash.input_hash(*args).each do |name, value| .(name => value) end config_attributes(*builder.config_names) end end |
#config_attributes(*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 an attribute to the list of attributes
The list of attributes represent attribute readers that class instances can respond to
Subclasses will respond to the same attributes as the parent class plus it’s own
This method does not add the method or .attr_reader
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sinclair/config_class.rb', line 33 def config_attributes(*attributes) @config_attributes ||= [] if attributes.present? new_attributes = attributes.map(&:to_sym) - @config_attributes @config_attributes.concat(new_attributes) end if superclass.is_a?(ConfigClass) (superclass.config_attributes.dup + @config_attributes).uniq else @config_attributes end end |
#options_class ⇒ Class<Sinclair::Options>
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 the options class exclusive to this configurable
The returned class is configured in parallel with the configurable itself
101 102 103 |
# File 'lib/sinclair/config_class.rb', line 101 def @options_class ||= Class.new(superclass.try(:options_class) || Options) end |