dry-types 1.0.0 → 1.0.1

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: '09c9bc944d01d8cb892cd29f540352981bc6e266ac7d2017cbd1827b7ca81b3c'
4
- data.tar.gz: 9a652f7888d52bdc6684b9ba142792460b45c1d27157d0176c0daa322af1826f
3
+ metadata.gz: 9bb3d91a31885a317b8fda3eef46f77b283abb3781c84124cc7ca0a5a2c30104
4
+ data.tar.gz: 88cd356e7878080570e5fa659f1403e01d8bc8a9654b3c5cfaf568c851d8e848
5
5
  SHA512:
6
- metadata.gz: 3252ede1f749a14dfd09dcc5ab6c9872a7dc5f50cb31858712dd76f4f927d133b9ce8d03bce042bfd2bd832b5e21cae7723abf93618d6d746b38506a0aeeefc1
7
- data.tar.gz: 1e71e67c449fadfa5989f211a019bf75b0c5dac6240934d819af2f4401622833e31304906f99dd8a2d9ac6e9f14a6bb07d37e2c63ce28408b7b685bd4d88a1dd
6
+ metadata.gz: 536386eba753a58a499c473d7f9e54da2bccf8597d80e3e225a036fb37acd886e0e9f75ceff497e81e6cb9a47141c2fdf4753f2bd521bf5a53424f768fc0cf0d
7
+ data.tar.gz: f74042df53c00159132ff2675206a393ca73a0d48ab84f7e6d58d56a51082e570932591279705ec993056b8e2720fd4572657b7bcb90596a16a7addaa7ac4bcf
@@ -1,3 +1,20 @@
1
+ # 1.0.1 2019-06-04
2
+
3
+ ## Added
4
+
5
+ - In the case of failure the constructor block can now pass a different value (flash-gordon)
6
+ ```ruby
7
+ not_empty_string = Types::String.constructor do |value, &failure|
8
+ value.strip.empty? ? failure.(nil) : value.strip
9
+ end
10
+ not_empty_string.(' ') { |v| v } # => nil
11
+ not_empty_string.lax.(' ') # => nil
12
+ not_empty_string.lax.(' foo ') # => "foo"
13
+ ```
14
+ - `Schema#strict` now accepts an boolean argument. If `fales` is passed this will turn a strict schema into a non-strict one (flash-gordon)
15
+
16
+ [Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-types/compare/v1.0.0...v1.0.1)
17
+
1
18
  # 1.0.0 2019-04-23
2
19
 
3
20
  ## Changed
@@ -30,7 +47,7 @@
30
47
 
31
48
  ## Added
32
49
 
33
- - API for custom constructor types was enhanced. If you pass your own callable to `.constructor` it can have a block in its signature. If a block is passed, you must call it on failied coercion, otherwise raise a type coercion error (flash-gordon)
50
+ - API for custom constructor types was enhanced. If you pass your own callable to `.constructor` it can have a block in its signature. If a block is passed, you must call it on failed coercion, otherwise raise a type coercion error (flash-gordon)
34
51
  Example:
35
52
  ```ruby
36
53
  proc do |input, &block|
@@ -107,6 +107,22 @@ module Dry
107
107
  def Map(key_type, value_type)
108
108
  Types['nominal.hash'].map(key_type, value_type)
109
109
  end
110
+
111
+ # # Builds a constrained nominal type accepting any value that
112
+ # # responds to given methods
113
+ # #
114
+ # # @example
115
+ # # Types::Callable = Types.Contract(:call)
116
+ # # Types::Contact = Types.Contract(:name, :address)
117
+ # #
118
+ # # @param methods [Array<String, Symbol>] Method names
119
+ # #
120
+ # # @return [Dry::Types::Contrained]
121
+ # def Contract(*methods)
122
+ # methods.reduce(Types['nominal.any']) do |type, method|
123
+ # type.constrained(respond_to: method)
124
+ # end
125
+ # end
110
126
  end
111
127
  end
112
128
  end
@@ -75,7 +75,7 @@ module Dry
75
75
  #
76
76
  # @api private
77
77
  def call_safe(input)
78
- coerced = fn.(input) { return yield }
78
+ coerced = fn.(input) { |output = input| return yield(output) }
79
79
  type.call_safe(coerced) { |output = coerced| yield(output) }
80
80
  end
81
81
 
@@ -175,8 +175,8 @@ module Dry
175
175
  # @return [Schema]
176
176
  #
177
177
  # @api public
178
- def strict
179
- with(strict: true)
178
+ def strict(strict = true)
179
+ with(strict: strict)
180
180
  end
181
181
 
182
182
  # Injects a key transformation function
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Types
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-23 00:00:00.000000000 Z
11
+ date: 2019-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby