dry-schema 1.13.2 → 1.13.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/README.md +1 -1
- data/lib/dry/schema/extensions/struct.rb +25 -3
- data/lib/dry/schema/key_validator.rb +2 -2
- data/lib/dry/schema/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01ee230572b92457f6619423c9963be605d79e86cfb4cef112767eda78e5223d
|
4
|
+
data.tar.gz: e9584df52d3c640691168703536546654a97eec2960fc96d932ea69ba5cedc50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4fa2334f3093e9a18ecea268e8f977204d40104f93c3db75c23bd82001b8b0636f9d8a4053f101b94e7a73982b5bdee67e65b5de13e7709bc1893f3a6c01061
|
7
|
+
data.tar.gz: 2ae6ef323db1a53ae6c375d2bdf1986379aacf5627385394549d784463fc6ebe621bcaaf73b391aa719661e66d47a7a52fd90b5539fe68e681fa4d90e268f2ca
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
[gem]: https://rubygems.org/gems/dry-schema
|
3
3
|
[actions]: https://github.com/dry-rb/dry-schema/actions
|
4
4
|
|
5
|
-
# dry-schema [][gem] [][gem] [][actions]
|
6
6
|
|
7
7
|
## Links
|
8
8
|
|
@@ -5,20 +5,42 @@ require "dry/struct"
|
|
5
5
|
module Dry
|
6
6
|
module Schema
|
7
7
|
module Macros
|
8
|
+
class StructToSchema < ::Dry::Struct::Compiler
|
9
|
+
def call(struct)
|
10
|
+
visit(struct.to_ast)
|
11
|
+
end
|
12
|
+
|
13
|
+
# strip away structs from AST
|
14
|
+
def visit_struct(node)
|
15
|
+
_, ast = node
|
16
|
+
visit(ast)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Hash.option :struct_compiler, default: proc { StructToSchema.new(schema_dsl.config.types) }
|
21
|
+
|
8
22
|
Hash.prepend(::Module.new {
|
9
23
|
def call(*args)
|
10
|
-
if args.size >= 1 &&
|
24
|
+
if args.size >= 1 && struct?(args[0])
|
11
25
|
if block_given?
|
12
26
|
raise ArgumentError, "blocks are not supported when using "\
|
13
27
|
"a struct class (#{name.inspect} => #{args[0]})"
|
14
28
|
end
|
15
29
|
|
16
|
-
|
17
|
-
|
30
|
+
schema = struct_compiler.(args[0])
|
31
|
+
|
32
|
+
super(schema, *args.drop(1))
|
33
|
+
type(schema_dsl.types[name].constructor(schema))
|
18
34
|
else
|
19
35
|
super
|
20
36
|
end
|
21
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def struct?(type)
|
42
|
+
type.is_a?(::Class) && type <= ::Dry::Struct
|
43
|
+
end
|
22
44
|
})
|
23
45
|
end
|
24
46
|
|
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.13.
|
4
|
+
version: 1.13.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|