Module: Super::Configuration::ConfigurationLogic::ClassMethods Private
- Defined in:
- lib/super/configuration.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
- #configure(attr, wrap: nil, enum: nil, **kwargs) ⇒ Object private
- #defaults ⇒ Object private
- #wraps ⇒ Object private
Instance Method Details
#configure(attr, wrap: nil, enum: nil, **kwargs) ⇒ 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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/super/configuration.rb', line 50 def configure(attr, wrap: nil, enum: nil, **kwargs) if kwargs.key?(:default) defaults[attr] = kwargs[:default] end define_method(attr) do if !configured?(attr) raise Error::UnconfiguredConfiguration, "unconfigured: #{attr}" end result = instance_variable_get("@#{attr}") if wrap.nil? result else wrap.call(result) end end define_method("#{attr}=") do |value| if enum.is_a?(Array) if !enum.include?(value) raise Error::InvalidConfiguration, "tried to set `#{attr}` to `#{value.inspect}`, " \ "expected: #{enum.join(", ")}" end end instance_variable_set("@#{attr}", value) value end end |
#defaults ⇒ 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.
42 43 44 |
# File 'lib/super/configuration.rb', line 42 def defaults @defaults ||= {} end |
#wraps ⇒ 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.
46 47 48 |
# File 'lib/super/configuration.rb', line 46 def wraps @wraps ||= {} end |