Class: Sinclair::Config::MethodsBuilder Private
- Defined in:
- lib/sinclair/config/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 inherited from Sinclair
Attributes included from OptionsParser
Class Method Summary collapse
-
.build(klass, *names, default) ⇒ MethodsBuilder
private
Instantiate method builder and build the methods.
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
A new instance of MethodsBuilder.
Methods inherited from Sinclair
#add_class_method, #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.
33 34 35 36 37 |
# File 'lib/sinclair/config/methods_builder.rb', line 33 def initialize(klass, *names) super(klass) @config_hash = Sinclair::InputHash.input_hash(*names) end |
Class Method Details
.build(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.
Instantiate method builder and build the methods
22 23 24 |
# File 'lib/sinclair/config/methods_builder.rb', line 22 def self.build(klass, *names) new(klass, *names).tap(&:build) 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
54 55 56 57 58 59 60 |
# File 'lib/sinclair/config/methods_builder.rb', line 54 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::Config::MethodsBuilder
65 66 67 |
# File 'lib/sinclair/config/methods_builder.rb', line 65 def config_names config_hash.keys end |