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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a921b130ff71b7911409536acb53ad6ef7abebf91d789ce7ce27fde24b90e95
4
- data.tar.gz: 9138f98a23846c1bb2474d2bb7b163dd0b0575e7c5911dd4b7ba05fc9deacb48
3
+ metadata.gz: 5eeeaaa196eb1b1b9d4f4408ec91e5716c6d9d19599e78d9f3f1ddaff9c08181
4
+ data.tar.gz: 47259a30a8855c530f530ba10f03c298c29dbf5018146b5432a4b4c0b95ac491
5
5
  SHA512:
6
- metadata.gz: a440d93c18f7e444293f6987b5655644856d15ebba9a32b6d01818e9546339d48d8b48f5b09023e3039271195c790ce6ec713ca2b05498202cfd45d628c12e2a
7
- data.tar.gz: '039ca399f75d3ee60be9c73399dfb15cadaf62d200254cdc1c873130b595c7715917eda4fa2e926e986c66817e6de972701c5b21cdc2e68ec282da71d040b46a'
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.respond_to?(:new) || type == Integer || type == Symbol
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
- # 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
-
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LowType
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
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: 1.0.2
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