Class: Dry::Configurable::Settings Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/dry/configurable/settings.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.

A collection of defined settings on a given class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = EMPTY_ARRAY) ⇒ Settings

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 Settings.



17
18
19
# File 'lib/dry/configurable/settings.rb', line 17

def initialize(settings = EMPTY_ARRAY)
  @settings = settings.each_with_object({}) { |s, m| m[s.name] = s }
end

Instance Attribute Details

#settingsObject (readonly)

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.



14
15
16
# File 'lib/dry/configurable/settings.rb', line 14

def settings
  @settings
end

Instance Method Details

#<<(setting) ⇒ 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.



28
29
30
31
32
# File 'lib/dry/configurable/settings.rb', line 28

def <<(setting)
  @data_class = nil
  settings[setting.name] = setting
  self
end

#[](name) ⇒ Setting?

Returns the setting for the given name, if found.

Returns:

  • (Setting, nil)

    the setting, or nil if not found



49
50
51
# File 'lib/dry/configurable/settings.rb', line 49

def [](name)
  settings[name]
end

#data_classClass

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 Data class with one member per defined setting, memoized for the lifetime of the schema. Invalidated when new settings are added.

Returns:

  • (Class)


40
41
42
# File 'lib/dry/configurable/settings.rb', line 40

def data_class
  @data_class ||= Data.define(*keys)
end

#eachObject



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

def each(&)
  settings.each_value(&)
end

#key?(name) ⇒ Boolean

Returns true if a setting for the given name is defined.

Returns:

  • (Boolean)


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

def key?(name)
  keys.include?(name)
end

#keysArray<Symbol>

Returns the list of defined setting names.

Returns:

  • (Array<Symbol>)


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

def keys
  settings.keys
end