class Dry::Configurable::Setting
A defined setting.
@api public
Constants
- DEFAULT_CONSTRUCTOR
- MUTABLE_VALUE_TYPES
- OPTIONS
Attributes
children[R]
@api public
constructor[R]
@api public
default[R]
@api public
mutable[R]
@api public
name[R]
@api public
options[R]
@api public
Public Class Methods
mutable_value?(value)
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 38 def self.mutable_value?(value) MUTABLE_VALUE_TYPES.any? { |type| value.is_a?(type) } end
new( name, default:, constructor: DEFAULT_CONSTRUCTOR, children: EMPTY_ARRAY, **options )
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 43 def initialize( name, default:, constructor: DEFAULT_CONSTRUCTOR, children: EMPTY_ARRAY, **options ) @name = name @default = default @mutable = children.any? || options.fetch(:mutable) { # Allow `cloneable` as an option alias for `mutable` options.fetch(:cloneable) { Setting.mutable_value?(default) } } @constructor = constructor @children = children @options = options end
Public Instance Methods
mutable?()
click to toggle source
@api public
# File lib/dry/configurable/setting.rb, line 67 def mutable? mutable end
Also aliased as: cloneable?
reader?()
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 62 def reader? options[:reader].equal?(true) end
to_value()
click to toggle source
@api private
# File lib/dry/configurable/setting.rb, line 73 def to_value if children.any? (options[:config_class] || Config).new(children) else value = default value = constructor.(value) unless value.eql?(Undefined) mutable? ? value.dup : value end end