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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40a701625494d482b8d9aa6092f8f924cd84ebc3310186e4dc9c1af38ff67cd4
4
- data.tar.gz: f24a27f11822f27177132eb8b840a9cdc4081867a171e338131a45e3b1a3b787
3
+ metadata.gz: ef26c686d314eec78cc49419d8f13d502d0a167f5b059961805754d38fd79a78
4
+ data.tar.gz: df781758ab9e3bb9a5d9a7c2119cd6dd3d080ec2cc123cf78aa9a90b75b660fd
5
5
  SHA512:
6
- metadata.gz: 62f84ed471ba858386cba1a1eb8876d62612701bc5760b1e60dd78cb37e10f1741228a4ec7ccbdf0eefbbe94cb13ffca12180ea1d8feedcd7d2c42ed627c4289
7
- data.tar.gz: 02c5577b08fc0ca6ab7e564efb550e11d80ff0521feeaff34aac291332f777507b04c40c9fea038976bacef187c5c769a6ea7a26060ba906cd0d95189b8c9c4c
6
+ metadata.gz: 941cd854ce780919c11335896b727eb8e4084e42d4c75ca2c4e563507d1ba7c2a580c19e8056e2cb45c093b76387921df1eeba71f82e4a176e57478d73c492e2
7
+ data.tar.gz: d47aa4998fd2154703359e382564321ad4dcd1cf6107990d5a7ec5b18634e8b1440d77fab5e0b165bfd6640ac114a771ed5e9a7dadcac284cc6941a43aaf0de4
@@ -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.class == ::Array && value.class == ::Array && array_types_match_values?(types: type, values: value)
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
- # TODO: Probably better to use an each that breaks early when types run out.
84
- types.zip(values) do |type, value|
85
- return false unless type === value
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LowType
4
- VERSION = '0.8.5'
4
+ VERSION = '0.8.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: low_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi