dry-schema 1.3.1 → 1.3.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: 7a41a84d107f4694b4009a58065e603b2489e87b55c91fba3884b2af2562d3ef
4
- data.tar.gz: fce0be0f38499c070f1fd1dc55c3c3407decef76aba778b3a27a839440bd888f
3
+ metadata.gz: a05f28f075af158f47da3ead0ea7441c8408d6d3aa9473481e47ceecdb94263f
4
+ data.tar.gz: a326e62e9af7360654a61204096d636acda23eabd497a1d2c847fc4afe8cfa98
5
5
  SHA512:
6
- metadata.gz: 3fb5a9045111eadb411f2afc39819dba78651a9170968b212eaebfd613376f7a22db40660e90b3ac6d264177a1e8d1ead05736f8ed2b13a5d3bdaf1e382f2c44
7
- data.tar.gz: c995cfb2e5e4c5f90d6109cbd01a81e627027ac730034422a3d1fbb791ab248bc9572d59fef5ff7c54cb69baeaeb6d8e21914e5641ba81f560e3cff4fc31673d
6
+ metadata.gz: 8b360914840bf0a6db5d5e3c2ba7464077ddc2c21664758256ef06f054e8a4a9fddc53fe8a13fc5a3456fb2794ac84051496471826ef49fb293a51074d2b9abf
7
+ data.tar.gz: '09862ce9b446d84a507846a47435c1d82d483531940fd6dc6bc6244bccf22cca430673a589950c74bbcbec35a771b01a5ffd00ac37decd256057e5da618ff8e9'
@@ -1,3 +1,22 @@
1
+ # 1.3.3 2019-08-14
2
+
3
+ ### Fixed
4
+
5
+ * Reject attempts to build a nested schema for array types built on `Dry::Types::Nominal` (fixed #171) (@flash-gordon)
6
+ * Current `I18n.locale` is now properly handled when caching message templates (@flash-gordon)
7
+ * Default processor uses strict types by default, which fixes various cases when `maybe` is used with a constructor type (@flash-gordon)
8
+ * Namespaced messages no longer causes a crash when used with nested schemas (fixed #176) (@solnic)
9
+
10
+ [Compare v1.3.2...v1.3.3](https://github.com/dry-rb/dry-schema/compare/v1.3.2...v1.3.3)
11
+
12
+ # 1.3.2 2019-08-01
13
+
14
+ ### Added
15
+
16
+ * Support for new predicates: `bytesize?`, `min_bytesize?` and `max_bytesize?` (@bmalinconico)
17
+
18
+ [Compare v1.3.1...v1.3.2](https://github.com/dry-rb/dry-schema/compare/v1.3.1...v1.3.2)
19
+
1
20
  # 1.3.1 2019-07-08
2
21
 
3
22
  ### Fixed
@@ -73,8 +73,12 @@ en:
73
73
 
74
74
  max_size?: "size cannot be greater than %{num}"
75
75
 
76
+ max_bytesize?: "bytesize cannot be greater than %{num}"
77
+
76
78
  min_size?: "size cannot be less than %{num}"
77
79
 
80
+ min_bytesize?: "bytesize cannot be less than %{num}"
81
+
78
82
  nil?: "cannot be defined"
79
83
 
80
84
  str?: "must be a string"
@@ -92,5 +96,10 @@ en:
92
96
  default: "length must be %{size}"
93
97
  range: "length must be within %{size_left} - %{size_right}"
94
98
 
99
+ bytesize?:
100
+ arg:
101
+ default: "must be %{size} bytes long"
102
+ range: "must be within %{size_left} - %{size_right} bytes long"
103
+
95
104
  not:
96
105
  empty?: "cannot be empty"
@@ -28,6 +28,12 @@ module Dry
28
28
  # @api private
29
29
  option :predicate_inferrer, default: proc { PredicateInferrer.new(compiler.predicates) }
30
30
 
31
+ # @!attribute [r] primitive_inferrer
32
+ # PrimitiveInferrer used to get a list of primitive classes from configured type
33
+ # @return [PrimitiveInferrer]
34
+ # @api private
35
+ option :primitive_inferrer, default: proc { PrimitiveInferrer.new }
36
+
31
37
  # @overload value(*predicates, **predicate_opts)
32
38
  # Set predicates without and with arguments
33
39
  #
@@ -10,12 +10,6 @@ module Dry
10
10
  #
11
11
  # @api private
12
12
  class Filled < Value
13
- # @!attribute [r] primitive_inferrer
14
- # PrimitiveInferrer used to get a list of primitive classes from configured type
15
- # @return [PrimitiveInferrer]
16
- # @api private
17
- option :primitive_inferrer, default: proc { PrimitiveInferrer.new }
18
-
19
13
  # @api private
20
14
  def call(*predicates, **opts, &block)
21
15
  ensure_valid_predicates(predicates)
@@ -28,8 +28,8 @@ module Dry
28
28
  definition = schema_dsl.new(&block)
29
29
  schema = definition.call
30
30
  type_schema =
31
- if array?
32
- parent_type.of(definition.type_schema)
31
+ if array?(parent_type)
32
+ build_array_type(parent_type, definition.type_schema)
33
33
  elsif redefined_schema?(args)
34
34
  parent_type.schema(definition.types)
35
35
  else
@@ -56,11 +56,6 @@ module Dry
56
56
  parent_type.optional?
57
57
  end
58
58
 
59
- # @api private
60
- def array?
61
- parent_type.respond_to?(:of)
62
- end
63
-
64
59
  # @api private
65
60
  def schema?
66
61
  parent_type.respond_to?(:schema)
@@ -17,8 +17,8 @@ module Dry
17
17
  current_type = schema_dsl.types[name]
18
18
 
19
19
  updated_type =
20
- if current_type.respond_to?(:of)
21
- current_type.of(schema.type_schema)
20
+ if array?(current_type)
21
+ build_array_type(current_type, schema.type_schema)
22
22
  else
23
23
  schema.type_schema
24
24
  end
@@ -39,6 +39,25 @@ module Dry
39
39
  self
40
40
  end
41
41
 
42
+ # @api private
43
+ def array?(type)
44
+ primitive_inferrer[type].eql?([::Array])
45
+ end
46
+
47
+ # @api private
48
+ def build_array_type(array_type, member)
49
+ if array_type.respond_to?(:of)
50
+ array_type.of(member)
51
+ else
52
+ raise ArgumentError, <<~ERROR.split("\n").join(' ')
53
+ Cannot define schema for a nominal array type.
54
+ Array types must be instances of Dry::Types::Array,
55
+ usually constructed with Types::Constructor(Array) { ... } or
56
+ Dry::Types['array'].constructor { ... }
57
+ ERROR
58
+ end
59
+ end
60
+
42
61
  # @api private
43
62
  def respond_to_missing?(meth, include_private = false)
44
63
  super || meth.to_s.end_with?(QUESTION_MARK)
@@ -92,7 +92,7 @@ module Dry
92
92
  #
93
93
  # @api public
94
94
  def call(predicate, options)
95
- cache.fetch_or_store([predicate, options.reject { |k,| k.equal?(:input) }]) do
95
+ cache.fetch_or_store(cache_key(predicate, options)) do
96
96
  text, meta = lookup(predicate, options)
97
97
  [Template[text], meta] if text
98
98
  end
@@ -167,6 +167,15 @@ module Dry
167
167
  config.default_locale
168
168
  end
169
169
 
170
+ # @api private
171
+ def cache_key(predicate, options)
172
+ if options.key?(:input)
173
+ [predicate, options.reject { |k,| k.equal?(:input) }]
174
+ else
175
+ [predicate, options]
176
+ end
177
+ end
178
+
170
179
  private
171
180
 
172
181
  # @api private
@@ -79,6 +79,15 @@ module Dry
79
79
  self
80
80
  end
81
81
 
82
+ # @api private
83
+ def cache_key(predicate, options)
84
+ if options[:locale]
85
+ super
86
+ else
87
+ [*super, I18n.locale]
88
+ end
89
+ end
90
+
82
91
  private
83
92
 
84
93
  # @api private
@@ -64,6 +64,11 @@ module Dry
64
64
  base_paths = messages.rule_lookup_paths(tokens)
65
65
  base_paths.map { |key| key.gsub('dry_schema', "dry_schema.#{namespace}") } + base_paths
66
66
  end
67
+
68
+ # @api private
69
+ def cache_key(predicate, options)
70
+ messages.cache_key(predicate, options)
71
+ end
67
72
  end
68
73
  end
69
74
  end
@@ -29,9 +29,10 @@ module Dry
29
29
  end
30
30
 
31
31
  # @api private
32
- def ast(input=Undefined)
32
+ def ast(input = Undefined)
33
33
  [:namespace, [namespace, rule.ast(input)]]
34
34
  end
35
+ alias_method :to_ast, :ast
35
36
  end
36
37
  end
37
38
  end
@@ -32,6 +32,7 @@ module Dry
32
32
  def visit_hash(_)
33
33
  Hash
34
34
  end
35
+ alias_method :visit_schema, :visit_hash
35
36
 
36
37
  # @api private
37
38
  def visit_array(_)
@@ -29,7 +29,7 @@ module Dry
29
29
  extend Dry::Configurable
30
30
 
31
31
  setting :key_map_type
32
- setting :type_registry_namespace, :nominal
32
+ setting :type_registry_namespace, :strict
33
33
  setting :filter_empty_string, false
34
34
 
35
35
  option :steps, default: -> { EMPTY_ARRAY.dup }
@@ -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 = :nominal)
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 = :nominal)
26
+ def initialize(types, namespace = :strict)
27
27
  @types = types
28
28
  @namespace = namespace
29
29
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = '1.3.1'
5
+ VERSION = '1.3.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.3.1
4
+ version: 1.3.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: 2019-07-08 00:00:00.000000000 Z
11
+ date: 2019-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby