Class: Sinclair::ConfigFactory::MethodsBuilder Private

Inherits:
Sinclair
  • Object
show all
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

VERSION

Instance Attribute Summary

Attributes included from OptionsParser

#options

Instance Method Summary collapse

Methods inherited from Sinclair

#add_method, #eval_and_add_method

Methods included from OptionsParser

#options_object

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.

to be added value when not configured

Parameters:

  • names (Array<Symbol,String>) —

    List of configuration names

  • default (Hash) —

    Configurations that will receive a default

Parameters:

  • klass (Class) —

    class inheriting from Sinclair::Config that will receive the methods



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

Returns:

See Also:



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

Returns:

  • (Array<String,Symbol>)


51
52
53
# File 'lib/sinclair/config_factory/methods_builder.rb', line 51

def config_names
  config_hash.keys
end