low_type 1.1.0 → 1.1.1
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/queries/type_query.rb +13 -13
- data/lib/syntax/syntax.rb +2 -2
- data/lib/type_expression.rb +1 -1
- 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: d8dae7f03ed51a1acea72d53deec50af0722e9c57ac8baab72297420bae36f4b
|
|
4
|
+
data.tar.gz: d7de0927fb139ac7d2b934c01f464224bb30fe2fbba6ca8b62a789955561e602
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4a91869b8c041091cd2dcadfb5ff931883041f7d57319b6cfb60b8ef7c1607924d81b93fc1a936724a3d577e904ed1d76c5bb03c89d6bf872e6446f0490f52e
|
|
7
|
+
data.tar.gz: d42d49968af57b0122e76449d01a5ed118bb4394d28fe42a6a9ec9095f6900ec02940e237e75fe3c1c4417b307c0b85497193a492b721e3c139902a15d92be7b
|
data/lib/queries/type_query.rb
CHANGED
|
@@ -6,30 +6,30 @@ module LowType
|
|
|
6
6
|
# TODO: Unit test.
|
|
7
7
|
class TypeQuery
|
|
8
8
|
class << self
|
|
9
|
-
def type?(
|
|
10
|
-
basic_type?(
|
|
9
|
+
def type?(expression)
|
|
10
|
+
basic_type?(expression:) || complex_type?(expression:)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def typed_array?(expression:)
|
|
14
|
+
expression.is_a?(Array) && (basic_type?(expression: expression.first) || expression.first.is_a?(TypeExpression))
|
|
11
15
|
end
|
|
12
16
|
|
|
13
17
|
def value?(value)
|
|
14
|
-
!basic_type?(
|
|
18
|
+
!basic_type?(expression: value) && !complex_type?(expression: value)
|
|
15
19
|
end
|
|
16
20
|
|
|
17
|
-
def complex_type?(
|
|
18
|
-
LowType::COMPLEX_TYPES.include?(
|
|
21
|
+
def complex_type?(expression:)
|
|
22
|
+
LowType::COMPLEX_TYPES.include?(expression) || typed_array?(expression:) || typed_hash?(expression:)
|
|
19
23
|
end
|
|
20
24
|
|
|
21
25
|
private
|
|
22
26
|
|
|
23
|
-
def basic_type?(
|
|
24
|
-
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def typed_array?(type:)
|
|
28
|
-
type.is_a?(Array) && (basic_type?(type: type.first) || type.first.is_a?(TypeExpression))
|
|
27
|
+
def basic_type?(expression:)
|
|
28
|
+
expression.instance_of?(Class)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def typed_hash?(
|
|
32
|
-
|
|
31
|
+
def typed_hash?(expression:)
|
|
32
|
+
expression.is_a?(Hash) && basic_type?(expression: expression.keys.first) && basic_type?(expression: expression.values.first)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
end
|
data/lib/syntax/syntax.rb
CHANGED
|
@@ -5,8 +5,8 @@ require_relative '../queries/type_query'
|
|
|
5
5
|
module LowType
|
|
6
6
|
module Syntax
|
|
7
7
|
refine Array.singleton_class do
|
|
8
|
-
def [](*
|
|
9
|
-
return TypeExpression.new(type: [*
|
|
8
|
+
def [](*expression)
|
|
9
|
+
return TypeExpression.new(type: [*expression]) if TypeQuery.type?(expression.first) || TypeQuery.typed_array?(expression:)
|
|
10
10
|
|
|
11
11
|
super
|
|
12
12
|
end
|
data/lib/type_expression.rb
CHANGED
|
@@ -122,7 +122,7 @@ module LowType
|
|
|
122
122
|
|
|
123
123
|
def type_matches_value?(type:, value:, proxy:)
|
|
124
124
|
if type.instance_of?(Class)
|
|
125
|
-
return type.match?(value:) if LowType::TypeQuery.complex_type?(type
|
|
125
|
+
return type.match?(value:) if LowType::TypeQuery.complex_type?(expression: type)
|
|
126
126
|
|
|
127
127
|
return type == value.class
|
|
128
128
|
elsif type.instance_of?(::LowType::TypeExpression)
|
data/lib/version.rb
CHANGED