19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/types/props/constructor.rb', line 19
def construct_props_without_defaults(instance, hash)
result = 0
props_without_defaults&.each_pair do |p, setter_proc|
begin
val = hash[p]
instance.instance_exec(val, &setter_proc)
if val || hash.key?(p)
result += 1
end
rescue TypeError, T::Props::InvalidValueError
if !hash.key?(p)
raise ArgumentError.new("Missing required prop `#{p}` for class `#{instance.class.name}`")
else
raise
end
end
end
result
end
|