Class: Dry::Configurable::Settings Private
- Inherits:
-
Object
- Object
- Dry::Configurable::Settings
- 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
- #settings ⇒ Object readonly private
Instance Method Summary collapse
- #<<(setting) ⇒ Object private
-
#[](name) ⇒ Setting?
Returns the setting for the given name, if found.
-
#data_class ⇒ Class
private
Returns a Data class with one member per defined setting, memoized for the lifetime of the schema.
- #each ⇒ Object
-
#initialize(settings = EMPTY_ARRAY) ⇒ Settings
constructor
private
A new instance of Settings.
-
#key?(name) ⇒ Boolean
Returns true if a setting for the given name is defined.
-
#keys ⇒ Array<Symbol>
Returns the list of defined setting names.
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
#settings ⇒ Object (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.
49 50 51 |
# File 'lib/dry/configurable/settings.rb', line 49 def [](name) settings[name] end |
#data_class ⇒ Class
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.
40 41 42 |
# File 'lib/dry/configurable/settings.rb', line 40 def data_class @data_class ||= Data.define(*keys) end |
#each ⇒ Object
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.
58 59 60 |
# File 'lib/dry/configurable/settings.rb', line 58 def key?(name) keys.include?(name) end |
#keys ⇒ Array<Symbol>
Returns the list of defined setting names.
67 68 69 |
# File 'lib/dry/configurable/settings.rb', line 67 def keys settings.keys end |