dry-schema 1.4.2 → 1.4.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: ebd83b8cd1025c9f732f593b47d52583455bac56def9866901a374cd9f24dc11
4
- data.tar.gz: def7d4f585ab856a055667474bc6cb59e7f012e13dcf0a4a9d17daa9b0ea53d1
3
+ metadata.gz: e079ef300d87844185052fe2a2c3e42230d29aefd409ec0acf6b9a45d3f296f5
4
+ data.tar.gz: cf34b9651357525e874109f4533e8c23c2f682ca33ffe90da0e789037491cfe2
5
5
  SHA512:
6
- metadata.gz: 77a2481151c16aa91e1a29a32e640adadfcefcbceacbd5e1e8cdfcd63c29d186dbc17640d9da0974c37a2e152440da723fd516cac7362cd195b24630011905d0
7
- data.tar.gz: c5cf256d2b61a3dc7b832f68d6ce64c735f00a7885f42a05f53f67a07ec6108322d996ea243387dc91b5acfbb57765129e8d25bfecbb2c151a5e18ac3c709c50
6
+ metadata.gz: 8bb4f328f94be77fcdeb4791c5227d694a93522880dbc7ed48684033e83f37ce62da9627820d2ba53606f231ac6e5add562a1d2cd502a851b8bab8415e748882
7
+ data.tar.gz: 1866a985a5bc45eb84c8670c8b67b209fd3397f656a82080debcc7cfa8a29284e7de6528a1b662eeafd61f0bbe2094328401ede95f381be7c765322de782690d
@@ -1,3 +1,31 @@
1
+ # 1.4.3 2020-01-08
2
+
3
+ ### Added
4
+
5
+ * Pattern matching for `Dry::Schema::Result` objects (@flash-gordon)
6
+ ```ruby
7
+ schema = Dry::Schema::Params { required(:name).filled }
8
+ case schema.('name' => 'John')
9
+ in name:
10
+ name # => 'John'
11
+ end
12
+ ```
13
+ Try it with monads!
14
+ * Shortcut for nested schemas in `value` and `maybe` macros (@waiting-for-dev)
15
+ ```ruby
16
+ Dry::Schema.Params do
17
+ required(:address).value(:hash) do
18
+ required(:city).filled
19
+ end
20
+ end
21
+ ```
22
+
23
+ ### Fixed
24
+
25
+ * Some keyword warnings that slipped into the previous release (@flash-gordon)
26
+
27
+ [Compare v1.4.2...v1.4.3](https://github.com/dry-rb/dry-schema/compare/v1.4.2...v1.4.3)
28
+
1
29
  # 1.4.2 2019-12-19
2
30
 
3
31
  ### Fixed
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2019 dry-rb team
3
+ Copyright (c) 2015-2020 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,6 +1,6 @@
1
1
  [gem]: https://rubygems.org/gems/dry-schema
2
2
  [actions]: https://github.com/dry-rb/dry-schema/actions
3
- [codeclimate]: https://codeclimate.com/github/dry-rb/dry-schema
3
+ [codacy]: https://www.codacy.com/gh/dry-rb/dry-schema
4
4
  [chat]: https://dry-rb.zulipchat.com
5
5
  [inchpages]: http://inch-ci.org/github/dry-rb/dry-schema
6
6
 
@@ -8,8 +8,8 @@
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/dry-schema.svg)][gem]
10
10
  [![CI Status](https://github.com/dry-rb/dry-schema/workflows/ci/badge.svg)][actions]
11
- [![Code Climate](https://codeclimate.com/github/dry-rb/dry-schema/badges/gpa.svg)][codeclimate]
12
- [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-schema/badges/coverage.svg)][codeclimate]
11
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/961f5c776f1d49218b2cede3745e059c)][codacy]
12
+ [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/961f5c776f1d49218b2cede3745e059c)][codacy]
13
13
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-schema.svg?branch=master)][inchpages]
14
14
 
15
15
  ## Links
@@ -19,7 +19,7 @@
19
19
 
20
20
  ## Supported Ruby versions
21
21
 
22
- This library officially supports following Ruby versions:
22
+ This library officially supports the following Ruby versions:
23
23
 
24
24
  * MRI >= `2.4`
25
25
  * jruby >= `9.2`
@@ -58,7 +58,7 @@ module Dry
58
58
 
59
59
  # @api private
60
60
  def inspect
61
- "#<#{self.class} #{to_h.map { |k,v| ["#{k}=", v.inspect] }.map(&:join).join(' ')}>"
61
+ "#<#{self.class} #{to_h.map { |k, v| ["#{k}=", v.inspect] }.map(&:join).join(' ')}>"
62
62
  end
63
63
 
64
64
  private
@@ -30,8 +30,7 @@ module Dry
30
30
  [
31
31
  [:not, [:predicate, [:nil?, [[:input, Undefined]]]]],
32
32
  trace.to_rule.to_ast
33
- ]
34
- ]
33
+ ]]
35
34
  end
36
35
  end
37
36
  end
@@ -27,13 +27,18 @@ module Dry
27
27
  end
28
28
 
29
29
  trace.evaluate(*predicates, **opts)
30
- trace.append(new(chain: false).instance_exec(&block)) if block
30
+
31
+ type_spec = opts[:type_spec]
32
+ if block && type_spec.equal?(:hash)
33
+ hash(&block)
34
+ elsif block
35
+ trace.append(new(chain: false).instance_exec(&block))
36
+ end
31
37
 
32
38
  if trace.captures.empty?
33
39
  raise ArgumentError, 'wrong number of arguments (given 0, expected at least 1)'
34
40
  end
35
41
 
36
- type_spec = opts[:type_spec]
37
42
  each(type_spec.type.member) if type_spec.respond_to?(:member)
38
43
 
39
44
  self
@@ -131,7 +131,7 @@ module Dry
131
131
  ).to_h
132
132
 
133
133
  template, meta = messages[predicate, options] ||
134
- raise(MissingMessageError.new(path, messages.looked_up_paths(predicate, options)))
134
+ raise(MissingMessageError.new(path, messages.looked_up_paths(predicate, options)))
135
135
 
136
136
  text = message_text(template, tokens, options)
137
137
 
@@ -17,13 +17,13 @@ module Dry
17
17
  #
18
18
  # @return [Array<Message>]
19
19
  attr_reader :messages
20
-
20
+
21
21
  # An internal hash that is filled in with dumped messages
22
22
  # when a message set is coerced to a hash
23
23
  #
24
24
  # @return [Hash<Symbol=>[Array,Hash]>]
25
25
  attr_reader :placeholders
26
-
26
+
27
27
  # Options hash
28
28
  #
29
29
  # @return [Hash]
@@ -33,7 +33,7 @@ module Dry
33
33
 
34
34
  opts = { locale: options.fetch(:locale, default_locale) }
35
35
 
36
- translation = t.(key, opts)
36
+ translation = t.(key, **opts)
37
37
  text_key = "#{key}.text"
38
38
 
39
39
  if !translation.is_a?(Hash) || !key?(text_key, opts)
@@ -44,7 +44,7 @@ module Dry
44
44
  end
45
45
 
46
46
  {
47
- text: t.(text_key, opts),
47
+ text: t.(text_key, **opts),
48
48
  meta: extract_meta(key, translation, opts)
49
49
  }
50
50
  end
@@ -121,7 +121,7 @@ module Dry
121
121
  def extract_meta(parent_key, translation, options)
122
122
  translation.keys.each_with_object({}) do |k, meta|
123
123
  meta_key = "#{parent_key}.#{k}"
124
- meta[k] = t.(meta_key, options) if k != :text && key?(meta_key, options)
124
+ meta[k] = t.(meta_key, **options) if k != :text && key?(meta_key, options)
125
125
  end
126
126
  end
127
127
  end
@@ -22,7 +22,7 @@ module Dry
22
22
  # @return [Hash]
23
23
  attr_reader :data
24
24
 
25
- # Translation function
25
+ # Translation function
26
26
  #
27
27
  # @return [Proc]
28
28
  attr_reader :t
@@ -136,6 +136,15 @@ module Dry
136
136
  "#<#{self.class}#{to_h.inspect} errors=#{errors.to_h.inspect}>"
137
137
  end
138
138
 
139
+ if RUBY_VERSION >= '2.7'
140
+ # Pattern matching support
141
+ #
142
+ # @api private
143
+ def deconstruct_keys(_)
144
+ output
145
+ end
146
+ end
147
+
139
148
  private
140
149
 
141
150
  # A list of failure ASTs produced by rule result objects
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = '1.4.2'
5
+ VERSION = '1.4.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.4.2
4
+ version: 1.4.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-12-19 00:00:00.000000000 Z
11
+ date: 2020-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  - !ruby/object:Gem::Version
247
247
  version: '0'
248
248
  requirements: []
249
- rubygems_version: 3.0.3
249
+ rubygems_version: 3.1.2
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: Coercion and validation for data structures