Class: Sinclair::Config::MethodsBuilder Private

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

Author:

  • darthjee

Constant Summary

Constants inherited from Sinclair

VERSION

Instance Attribute Summary

Attributes inherited from Sinclair

#klass

Attributes included from OptionsParser

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Sinclair

#add_class_method, #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.

Parameters:

  • names (Array<Symbol,String>)

    List of configuration names to be added

  • default (Hash)

    Configurations that will receive a default value value when not configured

Parameters:

  • klass (Class)

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



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

Parameters:

  • names (Array<Symbol,String>)

    List of configuration names to be added

  • default (Hash)

    Configurations that will receive a default value when not configured

Parameters:

  • klass (Class)

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

Returns:



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

#buildArray<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:



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_namesArray<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

Returns:

  • (Array<String,Symbol>)


65
66
67
# File 'lib/sinclair/config/methods_builder.rb', line 65

def config_names
  config_hash.keys
end