Class: Sinclair::ConfigFactory::MethodsBuilder Private
- Defined in:
- lib/sinclair/config_factory/methods_builder.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 adding method to configuration classes
Constant Summary
Constants inherited from Sinclair
Instance Attribute Summary
Attributes included from OptionsParser
Instance Method Summary collapse
-
#build ⇒ Array<MethodDefinition>
private
Build the methods in config class.
-
#config_names ⇒ Array<String,Symbol>
private
Returns the name of all configs defined by MethodsBuilder.
-
#initialize(klass, *names, default) ⇒ MethodsBuilder
constructor
private
to be added value when not configured.
Methods inherited from Sinclair
#add_method, #eval_and_add_method
Methods included from OptionsParser
Constructor Details
#initialize(klass, *names, default) ⇒ MethodsBuilder
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 MethodsBuilder.
17 18 19 20 21 22 23 |
# File 'lib/sinclair/config_factory/methods_builder.rb', line 17 def initialize(klass, *names) super(klass) @names = names @defaults = names.find { |arg| arg.is_a?(Hash) } || {} names.delete(defaults) end |
Instance Method Details
#build ⇒ Array<MethodDefinition>
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.
Build the methods in config class
Methods will be attribute readers that, when an attribute (instance variable) has never been defined, a default value is returned
Setting an instance variable to nil will not return default value.
If default value is required, Sinclair::Configurable#reset_config should be called
40 41 42 43 44 45 46 |
# File 'lib/sinclair/config_factory/methods_builder.rb', line 40 def build config_hash.each do |method, value| add_method(method, cached: :full) { value } end super end |
#config_names ⇒ Array<String,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.
Returns the name of all configs defined by Sinclair::ConfigFactory::MethodsBuilder
51 52 53 |
# File 'lib/sinclair/config_factory/methods_builder.rb', line 51 def config_names config_hash.keys end |