dry-schema 1.13.1 → 1.13.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1949729f55d95db1df478e3d2bf0077728c2cfaa5a66ac3d6d00bdbaaf55347
4
- data.tar.gz: 574d9ebd59457187c161730f8b2f232d299ff813fb6af10c680b57ce17c5ee46
3
+ metadata.gz: 01ee230572b92457f6619423c9963be605d79e86cfb4cef112767eda78e5223d
4
+ data.tar.gz: e9584df52d3c640691168703536546654a97eec2960fc96d932ea69ba5cedc50
5
5
  SHA512:
6
- metadata.gz: 520e01dc0ab8454bb981fcba032d3a1099fb7fad15b7eaf4008a094fae381178ab389b143a83b2f9f46522722aa14498bcf9a85e9708537d773a3b8f07c81635
7
- data.tar.gz: 6d3c13d9d1c13dd632368fd4a3ff34aaa8fec5573a5001540552eadd3debe413160d54bbc8051822deb029c9bf20ffe301a120dbd97f2a569eac398de767053e
6
+ metadata.gz: b4fa2334f3093e9a18ecea268e8f977204d40104f93c3db75c23bd82001b8b0636f9d8a4053f101b94e7a73982b5bdee67e65b5de13e7709bc1893f3a6c01061
7
+ data.tar.gz: 2ae6ef323db1a53ae6c375d2bdf1986379aacf5627385394549d784463fc6ebe621bcaaf73b391aa719661e66d47a7a52fd90b5539fe68e681fa4d90e268f2ca
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.13.2 2023-05-31
4
+
5
+
6
+ ### Fixed
7
+
8
+ - Fix custom predicates setting (via #460) (@solnic)
9
+
10
+
11
+ [Compare v1.13.1...v1.13.2](https://github.com/dry-rb/dry-schema/compare/v1.13.1...v1.13.2)
12
+
3
13
  ## 1.13.1 2023-04-07
4
14
 
5
15
 
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
 
@@ -22,7 +22,9 @@ module Dry
22
22
  # @return [Schema::PredicateRegistry]
23
23
  #
24
24
  # @api public
25
- setting :predicates, default: Schema::PredicateRegistry.new
25
+ setting :predicates, default: PredicateRegistry.new, constructor: -> predicates {
26
+ predicates.is_a?(PredicateRegistry) ? predicates : PredicateRegistry.new(predicates)
27
+ }
26
28
 
27
29
  # @!method types
28
30
  #
@@ -39,9 +39,6 @@ module Dry
39
39
 
40
40
  extend Dry::Initializer
41
41
 
42
- # @return [Compiler] The rule compiler object
43
- option :compiler, default: -> { Compiler.new }
44
-
45
42
  # @return [Compiler] The type of the processor (Params, JSON, or a custom sub-class)
46
43
  option :processor_type, default: -> { Processor }
47
44
 
@@ -84,6 +81,7 @@ module Dry
84
81
  def self.new(**options, &block)
85
82
  dsl = super
86
83
  dsl.instance_eval(&block) if block
84
+ dsl.instance_variable_set("@compiler", options[:compiler]) if options[:compiler]
87
85
  dsl
88
86
  end
89
87
 
@@ -106,6 +104,16 @@ module Dry
106
104
  self
107
105
  end
108
106
 
107
+ # @api private
108
+ def compiler
109
+ @compiler ||= Compiler.new(predicates)
110
+ end
111
+
112
+ # @api private
113
+ def predicates
114
+ @predicates ||= config.predicates
115
+ end
116
+
109
117
  # Return a macro with the provided name
110
118
  #
111
119
  # @param [Symbol] name
@@ -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
@@ -19,10 +19,10 @@ module Dry
19
19
  option :compiler, default: proc { Compiler.new }
20
20
 
21
21
  # @api private
22
- option :trace, default: proc { Trace.new }
22
+ option :schema_dsl, optional: true
23
23
 
24
24
  # @api private
25
- option :schema_dsl, optional: true
25
+ option :trace, default: proc { Trace.new(schema_dsl&.compiler || Compiler.new) }
26
26
 
27
27
  # @api private
28
28
  def new(**options)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = "1.13.1"
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.1
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-04-07 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