Sha256: 784801fda8dcd1912175cc1dce1b8dd369e09e9b31f452da41ff9ec019c7ca83
Contents?: true
Size: 565 Bytes
Versions: 7
Compression:
Stored size: 565 Bytes
Contents
module Dry::Initializer::Plugins # Plugin builds either chunk of code for the #initializer, # or a proc for the ##__after_initialize__ callback. class TypeConstraint < Base def call return unless settings.key? :type type = settings[:type] fail TypeConstraintError.new(name, type) unless type.respond_to? :call ivar = :"@#{name}" lambda do |*| value = instance_variable_get(ivar) return if value == Dry::Initializer::UNDEFINED instance_variable_set ivar, type.call(value) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems