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.



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

def <<(setting)
  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



37
38
39
# File 'lib/dry/configurable/settings.rb', line 37

def [](name)
  settings[name]
end

#each(&block) ⇒ Object



60
61
62
# File 'lib/dry/configurable/settings.rb', line 60

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

#key?(name) ⇒ Boolean

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

Returns:

  • (Boolean)


46
47
48
# File 'lib/dry/configurable/settings.rb', line 46

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

#keysArray<Symbol>

Returns the list of defined setting names.

Returns:

  • (Array<Symbol>)


55
56
57
# File 'lib/dry/configurable/settings.rb', line 55

def keys
  settings.keys
end