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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f38923174afc15c94df3839a0ab0501c8aecb4ebc5df7042edc6c6590744449b
4
- data.tar.gz: 97183a67cd62d595ba32413708b99c6d4c3d6760414f846f9a2ee12a1fd15615
3
+ metadata.gz: 01ee230572b92457f6619423c9963be605d79e86cfb4cef112767eda78e5223d
4
+ data.tar.gz: e9584df52d3c640691168703536546654a97eec2960fc96d932ea69ba5cedc50
5
5
  SHA512:
6
- metadata.gz: 70f7656a3c4af51c4d576d022ba552728831b35cadf29f2589706e979463a01d2a5eea1c5ed546759625431dc7114df41b2f1838e8bda2d1fa223c8573f5f8a1
7
- data.tar.gz: 6b639a89fb5df82cfcb546649a5cc172456537e11944913a48df2b88b99a04b0b09be262ce55224a1fdc7d87916e5cd5f6b73bad761972b010ca2034f7b13e77
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 Version](https://badge.fury.io/rb/dry-schema.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-schema/workflows/ci/badge.svg)][actions]
5
+ # dry-schema [![Gem Version](https://badge.fury.io/rb/dry-schema.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-schema/workflows/CI/badge.svg)][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 && args[0].is_a?(::Class) && args[0] <= ::Dry::Struct
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
- super(args[0].schema, *args.drop(1))
17
- type(schema_dsl.types[name].constructor(args[0].schema))
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
 
@@ -9,8 +9,8 @@ module Dry
9
9
  class KeyValidator
10
10
  extend Dry::Initializer
11
11
 
12
- INDEX_REGEX = /\[\d+\]/.freeze
13
- DIGIT_REGEX = /\A\d+\z/.freeze
12
+ INDEX_REGEX = /\[\d+\]/
13
+ DIGIT_REGEX = /\A\d+\z/
14
14
  BRACKETS = "[]"
15
15
 
16
16
  # @api private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = "1.13.2"
5
+ VERSION = "1.13.3"
6
6
  end
7
7
  end
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.2
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-05-31 00:00:00.000000000 Z
11
+ date: 2023-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby