low_type 0.8.5 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/type_expression.rb +12 -6
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ef26c686d314eec78cc49419d8f13d502d0a167f5b059961805754d38fd79a78
|
|
4
|
+
data.tar.gz: df781758ab9e3bb9a5d9a7c2119cd6dd3d080ec2cc123cf78aa9a90b75b660fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 941cd854ce780919c11335896b727eb8e4084e42d4c75ca2c4e563507d1ba7c2a580c19e8056e2cb45c093b76387921df1eeba71f82e4a176e57478d73c492e2
|
|
7
|
+
data.tar.gz: d47aa4998fd2154703359e382564321ad4dcd1cf6107990d5a7ec5b18634e8b1440d77fab5e0b165bfd6640ac114a771ed5e9a7dadcac284cc6941a43aaf0de4
|
data/lib/type_expression.rb
CHANGED
|
@@ -38,9 +38,9 @@ module LowType
|
|
|
38
38
|
|
|
39
39
|
@types.each do |type|
|
|
40
40
|
return true if LowType.type?(type) && type <= value.class # Example: HTML is a subclass of String and should pass as a String.
|
|
41
|
+
return true if ::Array === type && ::Array === value && array_types_match_values?(types: type, values: value)
|
|
41
42
|
|
|
42
43
|
# TODO: Shallow validation of enumerables could be made deeper with user config.
|
|
43
|
-
return true if type.class == ::Array && value.class == ::Array && type.first == value.first.class
|
|
44
44
|
if type.class == ::Hash && value.class == ::Hash && type.keys[0] == value.keys[0].class && type.values[0] == value.values[0].class
|
|
45
45
|
return true
|
|
46
46
|
end
|
|
@@ -56,8 +56,8 @@ module LowType
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
@types.each do |type|
|
|
59
|
-
return true if LowType.type?(type) && type == value.class
|
|
60
|
-
return true if type
|
|
59
|
+
return true if LowType.type?(type) && type == value.class
|
|
60
|
+
return true if ::Array === type && ::Array === value && array_types_match_values?(types: type, values: value)
|
|
61
61
|
|
|
62
62
|
# TODO: Shallow validation of hash could be made deeper with user config.
|
|
63
63
|
if type.class == ::Hash && value.class == ::Hash && type.keys[0] == value.keys[0].class && type.values[0] == value.values[0].class
|
|
@@ -80,10 +80,16 @@ module LowType
|
|
|
80
80
|
private
|
|
81
81
|
|
|
82
82
|
def array_types_match_values?(types:, values:)
|
|
83
|
-
#
|
|
84
|
-
types.
|
|
85
|
-
|
|
83
|
+
# [T, T, T]
|
|
84
|
+
if types.length > 1
|
|
85
|
+
types.each_with_index do |type, index|
|
|
86
|
+
return false unless type === values[index]
|
|
87
|
+
end
|
|
88
|
+
# [T]
|
|
89
|
+
elsif types.length == 1
|
|
90
|
+
return false unless types.first == values.first.class
|
|
86
91
|
end
|
|
92
|
+
# TODO: Deep type check (all elements for [T]).
|
|
87
93
|
|
|
88
94
|
true
|
|
89
95
|
end
|
data/lib/version.rb
CHANGED