Module: Dry::Configurable::ClassMethods Private

Includes:
Methods
Defined in:
lib/dry/configurable/class_methods.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods included from Methods

#configure, #finalize!

Instance Method Details

#__config_build__(settings = self.settings) ⇒ Object

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.



72
73
74
# File 'lib/dry/configurable/class_methods.rb', line 72

def __config_build__(settings = self.settings)
  __config_extension__.config_class.new(settings)
end

#__config_dsl__Object

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.



82
83
84
85
86
87
# File 'lib/dry/configurable/class_methods.rb', line 82

def __config_dsl__
  @__config_dsl__ ||= DSL.new(
    config_class: __config_extension__.config_class,
    default_undefined: __config_extension__.default_undefined
  )
end

#__config_extension__Object

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.



77
78
79
# File 'lib/dry/configurable/class_methods.rb', line 77

def __config_extension__
  @__config_extension__
end

#__config_reader__Object

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.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/dry/configurable/class_methods.rb', line 90

def __config_reader__
  @__config_reader__ ||=
    begin
      reader = Module.new do
        def self.define(name)
          define_method(name) do
            config[name]
          end
        end
      end

      if included_modules.include?(InstanceMethods)
        include(reader)
      end

      extend(reader)

      reader
    end
end

#configConfig

Return configuration

Returns:



67
68
69
# File 'lib/dry/configurable/class_methods.rb', line 67

def config
  @__config__ ||= __config_build__
end

#inherited(subclass) ⇒ Object

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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dry/configurable/class_methods.rb', line 11

def inherited(subclass)
  super

  subclass.instance_variable_set(:@__config_extension__, __config_extension__)

  new_settings = settings.dup
  subclass.instance_variable_set(:@__settings__, new_settings)

  # Only classes **extending** Dry::Configurable have class-level config. When
  # Dry::Configurable is **included**, the class-level config method is undefined because it
  # resides at the instance-level instead (see `Configurable.included`).
  if respond_to?(:config)
    subclass.instance_variable_set(:@__config__, config.dup_for_settings(new_settings))
  end
end

#setting(*args, **options) { ... } ⇒ Dry::Configurable::Config

Add a setting to the configuration

Parameters:

  • name (Mixed)

    The accessor key for the configuration value

  • default (Mixed)

    Default value for the setting

  • constructor (#call)

    Transformation given value will go through

  • reader (Boolean)

    Whether a reader accessor must be created

Yields:

  • A block can be given to add nested settings.

Returns:



43
44
45
46
47
48
49
50
51
# File 'lib/dry/configurable/class_methods.rb', line 43

def setting(*args, **options, &block)
  setting = __config_dsl__.setting(*args, **options, &block)

  settings << setting

  __config_reader__.define(setting.name) if setting.reader?

  self
end

#settingsSettings

Returns the defined settings for the class.

Returns:



58
59
60
# File 'lib/dry/configurable/class_methods.rb', line 58

def settings
  @__settings__ ||= Settings.new
end