low_type 1.0.2 → 1.0.3
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/low_type.rb +6 -4
- data/lib/redefiner.rb +1 -1
- data/lib/syntax/syntax.rb +19 -0
- data/lib/{syntax.rb → syntax/union_types.rb} +7 -23
- data/lib/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5eeeaaa196eb1b1b9d4f4408ec91e5716c6d9d19599e78d9f3f1ddaff9c08181
|
|
4
|
+
data.tar.gz: 47259a30a8855c530f530ba10f03c298c29dbf5018146b5432a4b4c0b95ac491
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4331980b4a8ab95a1bcf806a575580c05a9f8386da572cc16e0e978b68376f5609fadac585436e072bbd3d1dc77e09892e53abec6710dff77dbe67f165fb0eff
|
|
7
|
+
data.tar.gz: 6c62cd38cf093e6beef4c66bfa0cad1286da8d86feaa5bf6f2f229124ece2bcddb6ffc9acb216cc6b6c24f9b4935deeca39726c9f29ca27f38d0ed8ca97a508d
|
data/lib/low_type.rb
CHANGED
|
@@ -5,13 +5,15 @@ require_relative 'types/complex_types'
|
|
|
5
5
|
require_relative 'instance_types'
|
|
6
6
|
require_relative 'local_types'
|
|
7
7
|
require_relative 'redefiner'
|
|
8
|
-
require_relative 'syntax'
|
|
8
|
+
require_relative 'syntax/syntax'
|
|
9
9
|
require_relative 'type_expression'
|
|
10
10
|
require_relative 'value_expression'
|
|
11
11
|
|
|
12
12
|
module LowType
|
|
13
13
|
# We do as much as possible on class load rather than on instantiation to be thread-safe and efficient.
|
|
14
14
|
def self.included(klass)
|
|
15
|
+
require_relative 'syntax/union_types' if LowType.config.union_type_expressions
|
|
16
|
+
|
|
15
17
|
class << klass
|
|
16
18
|
def low_methods
|
|
17
19
|
@low_methods ||= {}
|
|
@@ -37,8 +39,8 @@ module LowType
|
|
|
37
39
|
# Public API.
|
|
38
40
|
|
|
39
41
|
def config
|
|
40
|
-
config = Struct.new(:deep_type_check, :severity_level)
|
|
41
|
-
@config ||= config.new(false, :error)
|
|
42
|
+
config = Struct.new(:deep_type_check, :severity_level, :union_type_expressions)
|
|
43
|
+
@config ||= config.new(false, :error, true)
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
def configure
|
|
@@ -58,7 +60,7 @@ module LowType
|
|
|
58
60
|
end
|
|
59
61
|
|
|
60
62
|
def basic_type?(type:)
|
|
61
|
-
type.
|
|
63
|
+
type.class == Class
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
def complex_type?(type:)
|
data/lib/redefiner.rb
CHANGED
|
@@ -4,7 +4,7 @@ require_relative 'factories/proxy_factory'
|
|
|
4
4
|
require_relative 'proxies/file_proxy'
|
|
5
5
|
require_relative 'proxies/method_proxy'
|
|
6
6
|
require_relative 'proxies/param_proxy'
|
|
7
|
-
require_relative 'syntax'
|
|
7
|
+
require_relative 'syntax/syntax'
|
|
8
8
|
require_relative 'type_expression'
|
|
9
9
|
|
|
10
10
|
module LowType
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LowType
|
|
4
|
+
module Syntax
|
|
5
|
+
refine Array.singleton_class do
|
|
6
|
+
def [](*types)
|
|
7
|
+
return LowType::TypeExpression.new(type: [*types]) if types.all? { |type| LowType.type?(type) }
|
|
8
|
+
super
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
refine Hash.singleton_class do
|
|
13
|
+
def [](type)
|
|
14
|
+
return LowType::TypeExpression.new(type:) if LowType.type?(type)
|
|
15
|
+
super
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
super
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
refine Hash.singleton_class do
|
|
14
|
-
def [](type)
|
|
15
|
-
return LowType::TypeExpression.new(type:) if LowType.type?(type)
|
|
16
|
-
|
|
17
|
-
super
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Refine doesn't support inheritence.
|
|
1
|
+
###
|
|
2
|
+
# Type expressions from union types.
|
|
3
|
+
#
|
|
4
|
+
# The "|" pipe syntax requires a monkey-patch but can be disabled if you don't need union types with default values.
|
|
5
|
+
# This is the only monkey-patch in the entire library and is a relatively harmless one.
|
|
6
|
+
# @see LowType.config.union_type_expressions
|
|
7
|
+
###
|
|
24
8
|
class Object
|
|
25
9
|
# For "Type | [type_expression/type/value]" situations, redirecting to or generating a type expression from types.
|
|
26
10
|
# "|" is not defined on Object class and this is the most compute-efficient way to achieve our goal (world peace).
|
data/lib/version.rb
CHANGED
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: 1.0.
|
|
4
|
+
version: 1.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
@@ -32,7 +32,8 @@ files:
|
|
|
32
32
|
- lib/proxies/param_proxy.rb
|
|
33
33
|
- lib/proxies/return_proxy.rb
|
|
34
34
|
- lib/redefiner.rb
|
|
35
|
-
- lib/syntax.rb
|
|
35
|
+
- lib/syntax/syntax.rb
|
|
36
|
+
- lib/syntax/union_types.rb
|
|
36
37
|
- lib/type_expression.rb
|
|
37
38
|
- lib/types/complex_types.rb
|
|
38
39
|
- lib/types/error_types.rb
|