dry-schema 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/lib/dry/schema/config.rb +10 -0
- data/lib/dry/schema/dsl.rb +4 -1
- data/lib/dry/schema/json.rb +1 -1
- data/lib/dry/schema/macros/dsl.rb +0 -1
- data/lib/dry/schema/macros/each.rb +4 -1
- data/lib/dry/schema/macros/filled.rb +5 -9
- data/lib/dry/schema/macros/schema.rb +32 -18
- data/lib/dry/schema/params.rb +1 -1
- data/lib/dry/schema/predicate_inferrer.rb +2 -1
- data/lib/dry/schema/predicate_registry.rb +5 -1
- data/lib/dry/schema/processor.rb +2 -1
- data/lib/dry/schema/type_container.rb +27 -0
- data/lib/dry/schema/type_registry.rb +1 -0
- data/lib/dry/schema/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7dce78efba45d06df82c2de21ab9da5208fef746034e1f3aba396221897540d
|
4
|
+
data.tar.gz: 85f73e374a58a8110a3d75f1617d3b015b07b0d3f9c44caf4dceced1930d88df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1317319cec5bacf68ec380166226382c4d10818db4b1a575841f04c43b12b2b420877121876ebb13ce85c59b7b88a375c1f9798523cc6fb123e274507203cd2
|
7
|
+
data.tar.gz: fa995747a3efd66855e6d8cbb7d07e6d2002cd9e459237acc58b8747dd7f7d728d4a5f57482269d25e3c63319110975e8b01ec713536defd31742812dc92e334
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,30 @@
|
|
1
|
+
# v1.2.0 2019-06-13
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* Ability to configure your own type container (@Morozzzko)
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
* `filled` macro no longer generates incorrect messages for arrays (issue #151) (@solnic)
|
10
|
+
* `filled` macro works correctly with constructor types (@solnic)
|
11
|
+
* `filled` works correctly with nested schemas (#149) (@solnic + @timriley)
|
12
|
+
* Custom array constructors are no longer discredited by `array` macro (@solnic)
|
13
|
+
* `BigDecimal` type is correctly handled by predicate inference (@solnic)
|
14
|
+
* Works with latest `dry-logic` which provides the new `respond_to?` predicate (#153) (@flash-gordon)
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
* Fixes related to `filled` restored pre-1.1.0 behavior of `:hints` which are again included (@solnic)
|
19
|
+
* `filled` no longer uses filter rules to handle empty strings in `Params` (@solnic)
|
20
|
+
|
21
|
+
[Compare v1.1.0...v1.2.0](https://github.com/dry-rb/dry-schema/compare/v1.1.0...v1.2.0)
|
22
|
+
|
1
23
|
# v1.1.0 2019-05-30
|
2
24
|
|
3
25
|
### Added
|
4
26
|
|
27
|
+
* `config.messages.default_locale` for setting...default locale (surprise, surprise) (solnic)
|
5
28
|
* `Config` exposes `predicates` setting too (solnic)
|
6
29
|
|
7
30
|
### Fixed
|
data/lib/dry/schema/config.rb
CHANGED
@@ -5,6 +5,7 @@ require 'dry/configurable'
|
|
5
5
|
|
6
6
|
require 'dry/schema/constants'
|
7
7
|
require 'dry/schema/predicate_registry'
|
8
|
+
require 'dry/schema/type_container'
|
8
9
|
|
9
10
|
module Dry
|
10
11
|
module Schema
|
@@ -26,6 +27,15 @@ module Dry
|
|
26
27
|
# @api public
|
27
28
|
setting(:predicates, Schema::PredicateRegistry.new)
|
28
29
|
|
30
|
+
# @!method types
|
31
|
+
#
|
32
|
+
# Return configured container with extra types
|
33
|
+
#
|
34
|
+
# @return [Hash]
|
35
|
+
#
|
36
|
+
# @api public
|
37
|
+
setting(:types, Dry::Types)
|
38
|
+
|
29
39
|
# @!method messages
|
30
40
|
#
|
31
41
|
# Return configuration for message backend
|
data/lib/dry/schema/dsl.rb
CHANGED
@@ -351,7 +351,10 @@ module Dry
|
|
351
351
|
#
|
352
352
|
# @api private
|
353
353
|
def type_registry
|
354
|
-
|
354
|
+
@type_registry ||= TypeRegistry.new(
|
355
|
+
config.types,
|
356
|
+
processor_type.config.type_registry_namespace
|
357
|
+
)
|
355
358
|
end
|
356
359
|
|
357
360
|
# Return key map type configured by the processor type
|
data/lib/dry/schema/json.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'dry/types/type'
|
3
4
|
require 'dry/schema/macros/dsl'
|
4
5
|
|
5
6
|
module Dry
|
@@ -12,7 +13,9 @@ module Dry
|
|
12
13
|
# @api private
|
13
14
|
def value(*args, **opts)
|
14
15
|
extract_type_spec(*args, set_type: false) do |*predicates, type_spec:|
|
15
|
-
|
16
|
+
if type_spec && !type_spec.is_a?(Dry::Types::Type)
|
17
|
+
type(schema_dsl.array[type_spec])
|
18
|
+
end
|
16
19
|
|
17
20
|
super(*predicates, type_spec: type_spec, **opts)
|
18
21
|
end
|
@@ -20,12 +20,8 @@ module Dry
|
|
20
20
|
def call(*predicates, **opts, &block)
|
21
21
|
ensure_valid_predicates(predicates)
|
22
22
|
|
23
|
-
if opts[:type_spec]
|
24
|
-
|
25
|
-
value(*predicates, **opts, &block)
|
26
|
-
else
|
27
|
-
value(predicates[0], :filled?, *predicates[1..predicates.size - 1], **opts, &block)
|
28
|
-
end
|
23
|
+
if opts[:type_spec] && !filter_empty_string?
|
24
|
+
value(predicates[0], :filled?, *predicates[1..predicates.size - 1], **opts, &block)
|
29
25
|
else
|
30
26
|
value(:filled?, *predicates, **opts, &block)
|
31
27
|
end
|
@@ -45,8 +41,8 @@ module Dry
|
|
45
41
|
# rubocop:enable Style/GuardClause
|
46
42
|
|
47
43
|
# @api private
|
48
|
-
def
|
49
|
-
!
|
44
|
+
def filter_empty_string?
|
45
|
+
!expected_primitives.include?(NilClass) && processor_config.filter_empty_string
|
50
46
|
end
|
51
47
|
|
52
48
|
# @api private
|
@@ -55,7 +51,7 @@ module Dry
|
|
55
51
|
end
|
56
52
|
|
57
53
|
# @api private
|
58
|
-
def
|
54
|
+
def expected_primitives
|
59
55
|
primitive_inferrer[schema_type]
|
60
56
|
end
|
61
57
|
|
@@ -14,31 +14,45 @@ module Dry
|
|
14
14
|
super(*args) unless args.empty?
|
15
15
|
|
16
16
|
if block
|
17
|
-
|
17
|
+
schema = define(&block)
|
18
|
+
trace << schema.to_rule
|
19
|
+
end
|
20
|
+
|
21
|
+
self
|
22
|
+
end
|
18
23
|
|
19
|
-
|
20
|
-
definition_schema = definition.type_schema
|
24
|
+
private
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
definition_schema
|
27
|
-
end
|
26
|
+
# @api private
|
27
|
+
def define(&block)
|
28
|
+
definition = schema_dsl.new(&block)
|
29
|
+
schema = definition.call
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
schema_type.optional
|
32
|
-
else
|
33
|
-
schema_type
|
34
|
-
end
|
31
|
+
type_schema = array? ? parent_type.of(definition.type_schema) : definition.type_schema
|
32
|
+
final_type = optional? ? type_schema.optional : type_schema
|
35
33
|
|
36
|
-
|
34
|
+
type(final_type)
|
37
35
|
|
38
|
-
|
36
|
+
if schema.filter_rules?
|
37
|
+
schema_dsl[name].filter { hash?.then(schema(schema.filter_schema)) }
|
39
38
|
end
|
40
39
|
|
41
|
-
|
40
|
+
schema
|
41
|
+
end
|
42
|
+
|
43
|
+
# @api private
|
44
|
+
def parent_type
|
45
|
+
schema_dsl.types[name]
|
46
|
+
end
|
47
|
+
|
48
|
+
# @api private
|
49
|
+
def optional?
|
50
|
+
parent_type.optional?
|
51
|
+
end
|
52
|
+
|
53
|
+
# @api private
|
54
|
+
def array?
|
55
|
+
parent_type.respond_to?(:of)
|
42
56
|
end
|
43
57
|
end
|
44
58
|
end
|
data/lib/dry/schema/params.rb
CHANGED
@@ -11,9 +11,13 @@ module Dry
|
|
11
11
|
# @api private
|
12
12
|
attr_reader :predicates
|
13
13
|
|
14
|
+
# @api private
|
15
|
+
attr_reader :has_predicate
|
16
|
+
|
14
17
|
# @api private
|
15
18
|
def initialize(predicates = Dry::Logic::Predicates)
|
16
19
|
@predicates = predicates
|
20
|
+
@has_predicate = ::Kernel.instance_method(:respond_to?).bind(@predicates)
|
17
21
|
end
|
18
22
|
|
19
23
|
# @api private
|
@@ -23,7 +27,7 @@ module Dry
|
|
23
27
|
|
24
28
|
# @api private
|
25
29
|
def key?(name)
|
26
|
-
|
30
|
+
has_predicate.(name)
|
27
31
|
end
|
28
32
|
|
29
33
|
# @api private
|
data/lib/dry/schema/processor.rb
CHANGED
@@ -4,6 +4,7 @@ require 'dry/configurable'
|
|
4
4
|
require 'dry/initializer'
|
5
5
|
|
6
6
|
require 'dry/schema/type_registry'
|
7
|
+
require 'dry/schema/type_container'
|
7
8
|
require 'dry/schema/rule_applier'
|
8
9
|
require 'dry/schema/key_coercer'
|
9
10
|
require 'dry/schema/value_coercer'
|
@@ -28,7 +29,7 @@ module Dry
|
|
28
29
|
extend Dry::Configurable
|
29
30
|
|
30
31
|
setting :key_map_type
|
31
|
-
setting :
|
32
|
+
setting :type_registry_namespace, :nominal
|
32
33
|
setting :filter_empty_string, false
|
33
34
|
|
34
35
|
option :steps, default: -> { EMPTY_ARRAY.dup }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry/container'
|
4
|
+
require 'dry/types'
|
5
|
+
|
6
|
+
module Dry
|
7
|
+
module Schema
|
8
|
+
# A class to build containers for custom types, which can be used in schemas
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# MyTypeContainer = Dry::Schema::TypeContainer.new
|
12
|
+
# MyTypeContainer.register('params.fancy_string', Types::FancyString)
|
13
|
+
#
|
14
|
+
# @api public
|
15
|
+
class TypeContainer
|
16
|
+
include Dry::Container::Mixin
|
17
|
+
|
18
|
+
def initialize(types_container = Dry::Types.container)
|
19
|
+
super()
|
20
|
+
|
21
|
+
merge(types_container)
|
22
|
+
end
|
23
|
+
|
24
|
+
alias registered? key?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
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.2.0
|
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-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -222,6 +222,7 @@ files:
|
|
222
222
|
- lib/dry/schema/result.rb
|
223
223
|
- lib/dry/schema/rule_applier.rb
|
224
224
|
- lib/dry/schema/trace.rb
|
225
|
+
- lib/dry/schema/type_container.rb
|
225
226
|
- lib/dry/schema/type_registry.rb
|
226
227
|
- lib/dry/schema/types.rb
|
227
228
|
- lib/dry/schema/value_coercer.rb
|