dry-schema 1.4.1 → 1.4.2

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: 130427870a9d2f124a3fbd39a55f700c2c905c34a6ffab9b5e12946321f647aa
4
- data.tar.gz: 71514ff28540db733a7d280656931c2e0f54b4f73b4a94b21e3a092234bfdfae
3
+ metadata.gz: ebd83b8cd1025c9f732f593b47d52583455bac56def9866901a374cd9f24dc11
4
+ data.tar.gz: def7d4f585ab856a055667474bc6cb59e7f012e13dcf0a4a9d17daa9b0ea53d1
5
5
  SHA512:
6
- metadata.gz: 42ed8a3c94600c20c2a1e843c76b2a945d9ef0b46bfa8379acf5369016899642525a9f3f6b574cc4e71b211ee690845abb0d164c07b681d19dfce474abd9ef92
7
- data.tar.gz: c0485078b33e945a2174c3ceb349c7e46c40ada2007c8a6e6f671c8e31c57e25e4142902e0ff9638f118179169162c8225292bde042dc2e2082b4dd078bfc36f
6
+ metadata.gz: 77a2481151c16aa91e1a29a32e640adadfcefcbceacbd5e1e8cdfcd63c29d186dbc17640d9da0974c37a2e152440da723fd516cac7362cd195b24630011905d0
7
+ data.tar.gz: c5cf256d2b61a3dc7b832f68d6ce64c735f00a7885f42a05f53f67a07ec6108322d996ea243387dc91b5acfbb57765129e8d25bfecbb2c151a5e18ac3c709c50
@@ -1,3 +1,14 @@
1
+ # 1.4.2 2019-12-19
2
+
3
+ ### Fixed
4
+
5
+ * `I18n` messages backend supports procs as text properly (issue #208) (@robhanlon22)
6
+ * `I18n` messages backend supports message meta-data (issue #210) (@robhanlon22)
7
+ * Fixed keyword warnings from MRI 2.7.0 (@flash-gordon)
8
+ * Array with a member works correctly with `maybe` (issue #206) (@solnic)
9
+
10
+ [Compare v1.4.1...v1.4.2](https://github.com/dry-rb/dry-schema/compare/v1.4.1...v1.4.2)
11
+
1
12
  # 1.4.1 2019-10-08
2
13
 
3
14
  ### Fixed
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 dry-rb team
3
+ Copyright (c) 2015-2019 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
  [gem]: https://rubygems.org/gems/dry-schema
2
- [travis]: https://travis-ci.com/dry-rb/dry-schema
3
2
  [actions]: https://github.com/dry-rb/dry-schema/actions
4
3
  [codeclimate]: https://codeclimate.com/github/dry-rb/dry-schema
5
4
  [chat]: https://dry-rb.zulipchat.com
@@ -8,7 +7,6 @@
8
7
  # dry-schema [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
9
8
 
10
9
  [![Gem Version](https://badge.fury.io/rb/dry-schema.svg)][gem]
11
- [![Travis Status](https://travis-ci.com/dry-rb/dry-schema.svg?branch=master)][travis]
12
10
  [![CI Status](https://github.com/dry-rb/dry-schema/workflows/ci/badge.svg)][actions]
13
11
  [![Code Climate](https://codeclimate.com/github/dry-rb/dry-schema/badges/gpa.svg)][codeclimate]
14
12
  [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-schema/badges/coverage.svg)][codeclimate]
@@ -30,7 +30,7 @@ module Dry
30
30
  #
31
31
  # @api public
32
32
  def self.define(**options, &block)
33
- DSL.new(options, &block).call
33
+ DSL.new(**options, &block).call
34
34
  end
35
35
 
36
36
  # Define a schema suitable for HTTP params
@@ -51,8 +51,6 @@ module Dry
51
51
 
52
52
  extend Dry::Initializer
53
53
 
54
- include ::Dry::Equalizer(:options)
55
-
56
54
  # @return [Compiler] The rule compiler object
57
55
  option :compiler, default: -> { Compiler.new }
58
56
 
@@ -275,8 +273,8 @@ module Dry
275
273
  # @return [Dry::Types::Safe]
276
274
  #
277
275
  # @api private
278
- def new(options = EMPTY_HASH, &block)
279
- self.class.new(options.merge(processor_type: processor_type, config: config), &block)
276
+ def new(**options, &block)
277
+ self.class.new(**options, processor_type: processor_type, config: config, &block)
280
278
  end
281
279
 
282
280
  # Set a type for the given key name
@@ -19,7 +19,7 @@ module Dry
19
19
  attr_reader :hints
20
20
 
21
21
  # @api private
22
- def initialize(*args)
22
+ def initialize(*, **)
23
23
  super
24
24
  @hints = @options.fetch(:hints, true)
25
25
  end
@@ -27,8 +27,8 @@ module Dry
27
27
  end
28
28
 
29
29
  # @api private
30
- def self.new(*args)
31
- fetch_or_store(*args) { super }
30
+ def self.new(*args, **kwargs)
31
+ fetch_or_store(args, kwargs) { super }
32
32
  end
33
33
 
34
34
  # @api private
@@ -65,8 +65,8 @@ module Dry
65
65
  end
66
66
 
67
67
  # @api private
68
- def new(new_opts = EMPTY_HASH)
69
- self.class.new(id, { name: name, coercer: coercer }.merge(new_opts))
68
+ def new(**new_opts)
69
+ self.class.new(id, name: name, coercer: coercer, **new_opts)
70
70
  end
71
71
 
72
72
  # @api private
@@ -28,8 +28,8 @@ module Dry
28
28
  option :schema_dsl, optional: true
29
29
 
30
30
  # @api private
31
- def new(options = EMPTY_HASH)
32
- self.class.new({ name: name, compiler: compiler, schema_dsl: schema_dsl }.merge(options))
31
+ def new(**options)
32
+ self.class.new(name: name, compiler: compiler, schema_dsl: schema_dsl, **options)
33
33
  end
34
34
 
35
35
  # @api private
@@ -57,11 +57,12 @@ module Dry
57
57
  # @return [Macros::Core]
58
58
  #
59
59
  # @api public
60
- def value(*predicates, **opts, &block)
60
+ def value(*predicates, &block)
61
61
  append_macro(Macros::Value) do |macro|
62
- macro.call(*predicates, **opts, &block)
62
+ macro.call(*predicates, &block)
63
63
  end
64
64
  end
65
+ ruby2_keywords :value if respond_to?(:ruby2_keywords, true)
65
66
 
66
67
  # Prepends `:filled?` predicate
67
68
  #
@@ -74,11 +75,12 @@ module Dry
74
75
  # @return [Macros::Core]
75
76
  #
76
77
  # @api public
77
- def filled(*args, **opts, &block)
78
+ def filled(*args, &block)
78
79
  append_macro(Macros::Filled) do |macro|
79
- macro.call(*args, **opts, &block)
80
+ macro.call(*args, &block)
80
81
  end
81
82
  end
83
+ ruby2_keywords :filled if respond_to?(:ruby2_keywords, true)
82
84
 
83
85
  # Specify a nested hash without enforced `hash?` type-check
84
86
  #
@@ -99,6 +101,7 @@ module Dry
99
101
  macro.call(*args, &block)
100
102
  end
101
103
  end
104
+ ruby2_keywords :schema if respond_to?(:ruby2_keywords, true)
102
105
 
103
106
  # Specify a nested hash with enforced `hash?` type-check
104
107
  #
@@ -113,6 +116,7 @@ module Dry
113
116
  macro.call(*args, &block)
114
117
  end
115
118
  end
119
+ ruby2_keywords :hash if respond_to?(:ruby2_keywords, true)
116
120
 
117
121
  # Specify predicates that should be applied to each element of an array
118
122
  #
@@ -136,6 +140,7 @@ module Dry
136
140
  macro.value(*args, &block)
137
141
  end
138
142
  end
143
+ ruby2_keywords :each if respond_to?(:ruby2_keywords, true)
139
144
 
140
145
  # Like `each` but sets `array?` type-check
141
146
  #
@@ -155,6 +160,7 @@ module Dry
155
160
  macro.value(*args, &block)
156
161
  end
157
162
  end
163
+ ruby2_keywords :array if respond_to?(:ruby2_keywords, true)
158
164
 
159
165
  # Set type spec
160
166
  #
@@ -30,6 +30,7 @@ module Dry
30
30
  (filter_schema_dsl[name] || filter_schema_dsl.optional(name)).value(*args, &block)
31
31
  self
32
32
  end
33
+ ruby2_keywords(:filter) if respond_to?(:ruby2_keywords, true)
33
34
 
34
35
  # @overload value(type_spec, *predicates, **predicate_opts)
35
36
  # Set type specification and predicates
@@ -87,7 +88,7 @@ module Dry
87
88
  def maybe(*args, **opts, &block)
88
89
  extract_type_spec(*args, nullable: true) do |*predicates, type_spec:|
89
90
  append_macro(Macros::Maybe) do |macro|
90
- macro.call(*predicates, **opts, &block)
91
+ macro.call(*predicates, type_spec: type_spec, **opts, &block)
91
92
  end
92
93
  end
93
94
  end
@@ -41,7 +41,7 @@ module Dry
41
41
  attr_reader :default_lookup_options
42
42
 
43
43
  # @api private
44
- def initialize(messages, options = EMPTY_HASH)
44
+ def initialize(messages, **options)
45
45
  super
46
46
  @options = options
47
47
  @default_lookup_options = options[:locale] ? { locale: locale } : EMPTY_HASH
@@ -55,7 +55,7 @@ module Dry
55
55
 
56
56
  return self if updated_opts.eql?(options)
57
57
 
58
- self.class.new(messages, updated_opts)
58
+ self.class.new(messages, **updated_opts)
59
59
  end
60
60
 
61
61
  # @api private
@@ -105,7 +105,7 @@ module Dry
105
105
  left, right = node.map { |n| visit(n, opts) }
106
106
 
107
107
  if [left, right].flatten.map(&:path).uniq.size == 1
108
- Message::Or.new(left, right, proc { |k| messages.translate(k, default_lookup_options) })
108
+ Message::Or.new(left, right, proc { |k| messages.translate(k, **default_lookup_options) })
109
109
  elsif right.is_a?(Array)
110
110
  right
111
111
  else
@@ -116,7 +116,7 @@ module Dry
116
116
  # @api private
117
117
  def visit_namespace(node, opts)
118
118
  ns, rest = node
119
- self.class.new(messages.namespaced(ns), options).visit(rest, opts)
119
+ self.class.new(messages.namespaced(ns), **options).visit(rest, opts)
120
120
  end
121
121
 
122
122
  # @api private
@@ -123,13 +123,7 @@ module Dry
123
123
 
124
124
  return unless path
125
125
 
126
- text = get(path, opts)
127
-
128
- if text.is_a?(Hash)
129
- text.values_at(:text, :meta)
130
- else
131
- [text, EMPTY_HASH]
132
- end
126
+ get(path, opts).values_at(:text, :meta)
133
127
  end
134
128
  # rubocop:enable Metrics/AbcSize
135
129
 
@@ -29,7 +29,24 @@ module Dry
29
29
  #
30
30
  # @api public
31
31
  def get(key, options = EMPTY_HASH)
32
- t.(key, locale: options.fetch(:locale, default_locale)) if key
32
+ return unless key
33
+
34
+ opts = { locale: options.fetch(:locale, default_locale) }
35
+
36
+ translation = t.(key, opts)
37
+ text_key = "#{key}.text"
38
+
39
+ if !translation.is_a?(Hash) || !key?(text_key, opts)
40
+ return {
41
+ text: translation,
42
+ meta: EMPTY_HASH
43
+ }
44
+ end
45
+
46
+ {
47
+ text: t.(text_key, opts),
48
+ meta: extract_meta(key, translation, opts)
49
+ }
33
50
  end
34
51
 
35
52
  # Check if given key is defined
@@ -100,6 +117,13 @@ module Dry
100
117
  I18n.backend.store_translations(locale, data[locale.to_s])
101
118
  end
102
119
  end
120
+
121
+ def extract_meta(parent_key, translation, options)
122
+ translation.keys.each_with_object({}) do |k, meta|
123
+ meta_key = "#{parent_key}.#{k}"
124
+ meta[k] = t.(meta_key, options) if k != :text && key?(meta_key, options)
125
+ end
126
+ end
103
127
  end
104
128
  end
105
129
  end
@@ -59,7 +59,7 @@ module Dry
59
59
 
60
60
  # @api private
61
61
  def call(data = EMPTY_HASH)
62
- data.empty? ? evaluator.() : evaluator.(data)
62
+ data.empty? ? evaluator.() : evaluator.(**data)
63
63
  end
64
64
  alias_method :[], :call
65
65
  end
@@ -62,7 +62,7 @@ module Dry
62
62
  # @api public
63
63
  def new(options = nil, &block)
64
64
  if options || block
65
- processor = super
65
+ processor = super(**(options || EMPTY_HASH))
66
66
  yield(processor) if block
67
67
  processor
68
68
  elsif definition
@@ -32,7 +32,7 @@ module Dry
32
32
  option :message_compiler
33
33
 
34
34
  # @api private
35
- def self.new(*args)
35
+ def self.new(*, **)
36
36
  result = super
37
37
  yield(result)
38
38
  result.freeze
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = '1.4.1'
5
+ VERSION = '1.4.2'
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.4.1
4
+ version: 1.4.2
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-10-08 00:00:00.000000000 Z
11
+ date: 2019-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby