dry-schema 1.3.2 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +178 -108
- data/LICENSE +1 -1
- data/README.md +2 -2
- data/lib/dry/schema.rb +1 -1
- data/lib/dry/schema/constants.rb +3 -2
- data/lib/dry/schema/dsl.rb +65 -20
- data/lib/dry/schema/extensions/hints/message_compiler_methods.rb +1 -1
- data/lib/dry/schema/key.rb +4 -4
- data/lib/dry/schema/macros/core.rb +2 -2
- data/lib/dry/schema/macros/dsl.rb +31 -8
- data/lib/dry/schema/macros/filled.rb +0 -7
- data/lib/dry/schema/macros/key.rb +2 -2
- data/lib/dry/schema/macros/schema.rb +2 -7
- data/lib/dry/schema/macros/value.rb +21 -2
- data/lib/dry/schema/message_compiler.rb +6 -5
- data/lib/dry/schema/messages/abstract.rb +43 -19
- data/lib/dry/schema/messages/i18n.rb +34 -1
- data/lib/dry/schema/messages/namespaced.rb +6 -1
- data/lib/dry/schema/messages/template.rb +1 -1
- data/lib/dry/schema/messages/yaml.rb +12 -0
- data/lib/dry/schema/namespaced_rule.rb +2 -1
- data/lib/dry/schema/predicate_registry.rb +2 -23
- data/lib/dry/schema/processor.rb +10 -27
- data/lib/dry/schema/processor_steps.rb +116 -0
- data/lib/dry/schema/result.rb +1 -1
- data/lib/dry/schema/type_registry.rb +2 -2
- data/lib/dry/schema/version.rb +1 -1
- metadata +5 -5
- data/lib/dry/schema/primitive_inferrer.rb +0 -98
data/lib/dry/schema/result.rb
CHANGED
@@ -18,12 +18,12 @@ module Dry
|
|
18
18
|
attr_reader :namespace
|
19
19
|
|
20
20
|
# @api private
|
21
|
-
def self.new(types = Dry::Types, namespace = :
|
21
|
+
def self.new(types = Dry::Types, namespace = :strict)
|
22
22
|
super
|
23
23
|
end
|
24
24
|
|
25
25
|
# @api private
|
26
|
-
def initialize(types, namespace = :
|
26
|
+
def initialize(types, namespace = :strict)
|
27
27
|
@types = types
|
28
28
|
@namespace = namespace
|
29
29
|
end
|
data/lib/dry/schema/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -106,14 +106,14 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: '1.
|
109
|
+
version: '1.2'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '1.
|
116
|
+
version: '1.2'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: bundler
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -217,8 +217,8 @@ files:
|
|
217
217
|
- lib/dry/schema/predicate.rb
|
218
218
|
- lib/dry/schema/predicate_inferrer.rb
|
219
219
|
- lib/dry/schema/predicate_registry.rb
|
220
|
-
- lib/dry/schema/primitive_inferrer.rb
|
221
220
|
- lib/dry/schema/processor.rb
|
221
|
+
- lib/dry/schema/processor_steps.rb
|
222
222
|
- lib/dry/schema/result.rb
|
223
223
|
- lib/dry/schema/rule_applier.rb
|
224
224
|
- lib/dry/schema/trace.rb
|
@@ -1,98 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dry/core/cache'
|
4
|
-
|
5
|
-
module Dry
|
6
|
-
module Schema
|
7
|
-
# PrimitiveInferrer is used internally by `Macros::Filled`
|
8
|
-
# for inferring a list of possible primitives that a given
|
9
|
-
# type can handle.
|
10
|
-
#
|
11
|
-
# @api private
|
12
|
-
class PrimitiveInferrer
|
13
|
-
extend Dry::Core::Cache
|
14
|
-
|
15
|
-
# Compiler reduces type AST into a list of primitives
|
16
|
-
#
|
17
|
-
# @api private
|
18
|
-
class Compiler
|
19
|
-
# @api private
|
20
|
-
def visit(node)
|
21
|
-
meth, rest = node
|
22
|
-
public_send(:"visit_#{meth}", rest)
|
23
|
-
end
|
24
|
-
|
25
|
-
# @api private
|
26
|
-
def visit_nominal(node)
|
27
|
-
type, _ = node
|
28
|
-
type
|
29
|
-
end
|
30
|
-
|
31
|
-
# @api private
|
32
|
-
def visit_hash(_)
|
33
|
-
Hash
|
34
|
-
end
|
35
|
-
|
36
|
-
# @api private
|
37
|
-
def visit_array(_)
|
38
|
-
Array
|
39
|
-
end
|
40
|
-
|
41
|
-
# @api private
|
42
|
-
def visit_lax(node)
|
43
|
-
visit(node)
|
44
|
-
end
|
45
|
-
|
46
|
-
# @api private
|
47
|
-
def visit_constructor(node)
|
48
|
-
other, * = node
|
49
|
-
visit(other)
|
50
|
-
end
|
51
|
-
|
52
|
-
# @api private
|
53
|
-
def visit_enum(node)
|
54
|
-
other, * = node
|
55
|
-
visit(other)
|
56
|
-
end
|
57
|
-
|
58
|
-
# @api private
|
59
|
-
def visit_sum(node)
|
60
|
-
left, right = node
|
61
|
-
|
62
|
-
[visit(left), visit(right)].flatten(1)
|
63
|
-
end
|
64
|
-
|
65
|
-
# @api private
|
66
|
-
def visit_constrained(node)
|
67
|
-
other, * = node
|
68
|
-
visit(other)
|
69
|
-
end
|
70
|
-
|
71
|
-
# @api private
|
72
|
-
def visit_any(_)
|
73
|
-
Object
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# @return [Compiler]
|
78
|
-
# @api private
|
79
|
-
attr_reader :compiler
|
80
|
-
|
81
|
-
# @api private
|
82
|
-
def initialize
|
83
|
-
@compiler = Compiler.new
|
84
|
-
end
|
85
|
-
|
86
|
-
# Infer predicate identifier from the provided type
|
87
|
-
#
|
88
|
-
# @return [Symbol]
|
89
|
-
#
|
90
|
-
# @api private
|
91
|
-
def [](type)
|
92
|
-
self.class.fetch_or_store(type.hash) do
|
93
|
-
Array(compiler.visit(type.to_ast)).freeze
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|