class Dry::Configurable::Setting
This class represents a setting and is used internally.
@api private
Constants
- CLONEABLE_VALUE_TYPES
- DEFAULT_CONSTRUCTOR
- OPTIONS
Attributes
default[R]
@api private
input[R]
@api private
name[R]
@api private
options[R]
@api private
writer_name[R]
@api private
Public Class Methods
cloneable_value?(value)
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 57 def self.cloneable_value?(value) CLONEABLE_VALUE_TYPES.any? { |type| value.is_a?(type) } end
new(name, input: Undefined, default: Undefined, **options)
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 62 def initialize(name, input: Undefined, default: Undefined, **options) @name = name @writer_name = :"#{name}=" @input = input @default = default @options = options evaluate if input_defined? end
Public Instance Methods
cloneable?()
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 118 def cloneable? if options.key?(:cloneable) # Return cloneable option if explicitly set options[:cloneable] else # Otherwise, infer cloneable from any of the input, default, or value Setting.cloneable_value?(input) || Setting.cloneable_value?(default) || ( evaluated? && Setting.cloneable_value?(value) ) end end
constructor()
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 103 def constructor options[:constructor] || DEFAULT_CONSTRUCTOR end
evaluated?()
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 83 def evaluated? instance_variable_defined?(:@value) end
input_defined?()
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 73 def input_defined? !input.equal?(Undefined) end
nested(settings)
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 88 def nested(settings) Nested.new(name, input: settings, **options) end
pristine()
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 93 def pristine with(input: Undefined) end
reader?()
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 108 def reader? options[:reader].equal?(true) end
value()
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 78 def value @value ||= evaluate end
with(new_opts)
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 98 def with(new_opts) self.class.new(name, input: input, default: default, **options, **new_opts) end
writer?(meth)
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 113 def writer?(meth) writer_name.equal?(meth) end
Private Instance Methods
evaluate()
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 146 def evaluate @value = constructor[Undefined.coalesce(input, default, nil)] end
initialize_copy(source)
click to toggle source
@api private
Calls superclass method
# File lib/dry/configurable/setting.rb, line 133 def initialize_copy(source) super @options = source.options.dup if source.cloneable? @input = source.input.dup @default = source.default.dup @value = source.value.dup if source.evaluated? end end