dry-types 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/---bug-report.md +1 -5
- data/.github/workflows/custom_ci.yml +2 -2
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +2 -0
- data/README.md +3 -4
- data/docsite/source/hash-schemas.html.md +1 -1
- data/dry-types.gemspec +1 -1
- data/lib/dry/types/builder_methods.rb +5 -1
- data/lib/dry/types/coercions.rb +6 -0
- data/lib/dry/types/coercions/params.rb +1 -1
- data/lib/dry/types/constrained.rb +1 -1
- data/lib/dry/types/constructor.rb +1 -1
- data/lib/dry/types/constructor/function.rb +1 -1
- data/lib/dry/types/default.rb +2 -2
- data/lib/dry/types/enum.rb +1 -1
- data/lib/dry/types/errors.rb +5 -5
- data/lib/dry/types/extensions/maybe.rb +1 -1
- data/lib/dry/types/lax.rb +1 -1
- data/lib/dry/types/nominal.rb +1 -1
- data/lib/dry/types/result.rb +2 -2
- data/lib/dry/types/schema/key.rb +5 -1
- data/lib/dry/types/sum.rb +1 -1
- data/lib/dry/types/version.rb +1 -1
- metadata +4 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b3fc7a2d5685f6e867418934765d0e3a4ecfbc5b62385ee371a38e15c09e9b1
|
4
|
+
data.tar.gz: 07ef4d9b60132cf459fbf18709e44b275e23f94141a3dc975d2eb50e7ac500e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b82208815b88c0c3291b4bb6db0ddf781d2cd13fad10e98b265b79bf070a2099c5a010cb20a313f9f3833a6b6f6ce2839938a51c34d73a1eaa4eaf2952868af
|
7
|
+
data.tar.gz: cccb4e835c977bfa978e4fd7d9d253810e9c83b9e5b181bb44b544caff966bd71957c7d730de17f2d5081f05a0be527495bf16b6222bbbe3657fa897fc33e085
|
@@ -9,11 +9,7 @@ assignees: ''
|
|
9
9
|
|
10
10
|
**Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
|
11
11
|
|
12
|
-
For more information see
|
13
|
-
|
14
|
-
**Before you report**
|
15
|
-
|
16
|
-
:warning: If you have a problem related to a schema, please **report it under [dry-schema issues](https://github.com/dry-rb/dry-schema/issues/new?assignees=&labels=bug&template=---bug-report.md&title=)** instead.
|
12
|
+
For more information see `CONTRIBUTING.md`.
|
17
13
|
|
18
14
|
**Describe the bug**
|
19
15
|
|
@@ -3,7 +3,7 @@ name: ci
|
|
3
3
|
on:
|
4
4
|
push:
|
5
5
|
paths:
|
6
|
-
- .github/workflows/
|
6
|
+
- .github/workflows/custom_ci.yml
|
7
7
|
- lib/**
|
8
8
|
- spec/**
|
9
9
|
|
@@ -57,7 +57,7 @@ jobs:
|
|
57
57
|
strategy:
|
58
58
|
fail-fast: false
|
59
59
|
matrix:
|
60
|
-
image: ["jruby:9.2.
|
60
|
+
image: ["jruby:9.2.9", "ruby:rc"]
|
61
61
|
dry_logic_from_master: ["true", "false"]
|
62
62
|
container:
|
63
63
|
image: ${{matrix.image}}
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# 1.2.2 2019-12-14
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
|
5
|
+
- `Types.Contructor` doesn't re-wrap class instances implementing type interface, this fixes some quirks in dry-struct (flash-gordon)
|
6
|
+
|
7
|
+
## Changed
|
8
|
+
|
9
|
+
- Types now use immutable equalizers. This should improve performance in certain cases e.g. in ROM (flash-gordon)
|
10
|
+
- Attempting to use non-symbol keys in hash schemas raises an error. We always supported only symbols as keys but there was no check, now it'll throw an argument error. If you want to convert strings to symbols, use `Hash#with_key_transform` (flash-gordon)
|
11
|
+
- Params and JSON types accept Time/Date/Datetime instances and boolean values. This can be useful in tests but we discourage you from relying on this behavior in production code. For example, building structs with `Params` types is considered a smell. There are dedicated tools for coercion, namely dry-schema and dry-validation. Be responsible user of dry-types! ❤ (flash-gordon)
|
12
|
+
|
13
|
+
[Compare v1.2.1...v1.2.2](https://github.com/dry-rb/dry-types/compare/v1.2.1...v1.2.2)
|
14
|
+
|
1
15
|
# 1.2.1 2019-11-07
|
2
16
|
|
3
17
|
## Fixed
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
[gem]: https://rubygems.org/gems/dry-types
|
2
|
-
[
|
2
|
+
[ci]: https://github.com/dry-rb/dry-types/actions?query=workflow%3Aci
|
3
3
|
[codeclimate]: https://codeclimate.com/github/dry-rb/dry-types
|
4
|
-
[coveralls]: https://coveralls.io/r/dry-rb/dry-types
|
5
4
|
[inchpages]: http://inch-ci.org/github/dry-rb/dry-types
|
6
5
|
[chat]: https://dry-rb.zulipchat.com
|
7
6
|
|
8
7
|
# dry-types [![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-types.svg)][gem]
|
11
|
-
[![Build Status](https://
|
10
|
+
[![Build Status](https://github.com/dry-rb/dry-types/workflows/ci/badge.svg)][ci]
|
12
11
|
[![Code Climate](https://codeclimate.com/github/dry-rb/dry-types/badges/gpa.svg)][codeclimate]
|
13
12
|
[![Test Coverage](https://codeclimate.com/github/dry-rb/dry-types/badges/coverage.svg)][codeclimate]
|
14
13
|
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-types.svg?branch=master)][inchpages]
|
15
14
|
|
16
15
|
## Links
|
17
16
|
|
18
|
-
|
17
|
+
- [Documentation](http://dry-rb.org/gems/dry-types)
|
19
18
|
|
20
19
|
## Development
|
21
20
|
|
@@ -143,7 +143,7 @@ user_hash[{}]
|
|
143
143
|
Type transformations work perfectly with inheritance, you don't have to define same rules more than once:
|
144
144
|
|
145
145
|
```ruby
|
146
|
-
SymbolizeAndOptionalSchema = Types::Hash
|
146
|
+
SymbolizeAndOptionalSchema = Types::Hash
|
147
147
|
.schema({})
|
148
148
|
.with_key_transform(&:to_sym)
|
149
149
|
.with_type_transform { |type| type.required(false) }
|
data/dry-types.gemspec
CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
36
36
|
spec.add_runtime_dependency 'dry-container', '~> 0.3'
|
37
37
|
spec.add_runtime_dependency 'dry-core', '~> 0.4', '>= 0.4.4'
|
38
|
-
spec.add_runtime_dependency 'dry-equalizer', '~> 0.
|
38
|
+
spec.add_runtime_dependency 'dry-equalizer', '~> 0.3'
|
39
39
|
spec.add_runtime_dependency 'dry-inflector', '~> 0.1', '>= 0.1.2'
|
40
40
|
spec.add_runtime_dependency 'dry-logic', '~> 1.0', '>= 1.0.2'
|
41
41
|
|
@@ -83,7 +83,11 @@ module Dry
|
|
83
83
|
# @return [Dry::Types::Type]
|
84
84
|
def Constructor(klass, cons = nil, &block)
|
85
85
|
if klass.is_a?(Type)
|
86
|
-
|
86
|
+
if cons || block
|
87
|
+
klass.constructor(cons || block)
|
88
|
+
else
|
89
|
+
klass
|
90
|
+
end
|
87
91
|
else
|
88
92
|
Nominal(klass).constructor(cons || block || klass.method(:new))
|
89
93
|
end
|
data/lib/dry/types/coercions.rb
CHANGED
@@ -39,6 +39,8 @@ module Dry
|
|
39
39
|
rescue ArgumentError, RangeError => e
|
40
40
|
CoercionError.handle(e, &block)
|
41
41
|
end
|
42
|
+
elsif input.is_a?(::Date)
|
43
|
+
input
|
42
44
|
elsif block_given?
|
43
45
|
yield
|
44
46
|
else
|
@@ -60,6 +62,8 @@ module Dry
|
|
60
62
|
rescue ArgumentError => e
|
61
63
|
CoercionError.handle(e, &block)
|
62
64
|
end
|
65
|
+
elsif input.is_a?(::DateTime)
|
66
|
+
input
|
63
67
|
elsif block_given?
|
64
68
|
yield
|
65
69
|
else
|
@@ -81,6 +85,8 @@ module Dry
|
|
81
85
|
rescue ArgumentError => e
|
82
86
|
CoercionError.handle(e, &block)
|
83
87
|
end
|
88
|
+
elsif input.is_a?(::Time)
|
89
|
+
input
|
84
90
|
elsif block_given?
|
85
91
|
yield
|
86
92
|
else
|
@@ -14,7 +14,7 @@ module Dry
|
|
14
14
|
FALSE_VALUES = %w[0 off Off OFF f false False FALSE F n no No NO N].freeze
|
15
15
|
BOOLEAN_MAP = ::Hash[
|
16
16
|
TRUE_VALUES.product([true]) + FALSE_VALUES.product([false])
|
17
|
-
].freeze
|
17
|
+
].merge(true => true, false => false).freeze
|
18
18
|
|
19
19
|
extend Coercions
|
20
20
|
|
data/lib/dry/types/default.rb
CHANGED
@@ -10,7 +10,7 @@ module Dry
|
|
10
10
|
class Default
|
11
11
|
# @api private
|
12
12
|
class Callable < Default
|
13
|
-
include Dry::Equalizer(:type, inspect: false)
|
13
|
+
include Dry::Equalizer(:type, inspect: false, immutable: true)
|
14
14
|
|
15
15
|
# Evaluates given callable
|
16
16
|
# @return [Object]
|
@@ -23,7 +23,7 @@ module Dry
|
|
23
23
|
include Decorator
|
24
24
|
include Builder
|
25
25
|
include Printable
|
26
|
-
include Dry::Equalizer(:type, :value, inspect: false)
|
26
|
+
include Dry::Equalizer(:type, :value, inspect: false, immutable: true)
|
27
27
|
|
28
28
|
# @return [Object]
|
29
29
|
attr_reader :value
|
data/lib/dry/types/enum.rb
CHANGED
data/lib/dry/types/errors.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Dry
|
4
4
|
module Types
|
5
|
-
extend Dry::Core::ClassAttributes
|
5
|
+
extend ::Dry::Core::ClassAttributes
|
6
6
|
|
7
7
|
# @!attribute [r] namespace
|
8
8
|
# @return [Container{String => Nominal}]
|
@@ -12,7 +12,7 @@ module Dry
|
|
12
12
|
|
13
13
|
# Base class for coercion errors raise by dry-types
|
14
14
|
#
|
15
|
-
class CoercionError < StandardError
|
15
|
+
class CoercionError < ::StandardError
|
16
16
|
# @api private
|
17
17
|
def self.handle(exception, meta: Undefined)
|
18
18
|
if block_given?
|
@@ -34,7 +34,7 @@ module Dry
|
|
34
34
|
# @api private
|
35
35
|
def initialize(message, meta: Undefined, backtrace: Undefined)
|
36
36
|
unless message.is_a?(::String)
|
37
|
-
raise ArgumentError, "message must be a string, #{message.class} given"
|
37
|
+
raise ::ArgumentError, "message must be a string, #{message.class} given"
|
38
38
|
end
|
39
39
|
|
40
40
|
super(message)
|
@@ -74,9 +74,9 @@ module Dry
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
MapError = Class.new(CoercionError)
|
77
|
+
MapError = ::Class.new(CoercionError)
|
78
78
|
|
79
|
-
SchemaKeyError = Class.new(CoercionError)
|
79
|
+
SchemaKeyError = ::Class.new(CoercionError)
|
80
80
|
private_constant(:SchemaKeyError)
|
81
81
|
|
82
82
|
class MissingKeyError < SchemaKeyError
|
data/lib/dry/types/lax.rb
CHANGED
data/lib/dry/types/nominal.rb
CHANGED
@@ -19,7 +19,7 @@ module Dry
|
|
19
19
|
include Meta
|
20
20
|
include Builder
|
21
21
|
include Printable
|
22
|
-
include Dry::Equalizer(:primitive, :options, :meta, inspect: false)
|
22
|
+
include Dry::Equalizer(:primitive, :options, :meta, inspect: false, immutable: true)
|
23
23
|
|
24
24
|
# @return [Class]
|
25
25
|
attr_reader :primitive
|
data/lib/dry/types/result.rb
CHANGED
@@ -8,7 +8,7 @@ module Dry
|
|
8
8
|
#
|
9
9
|
# @api public
|
10
10
|
class Result
|
11
|
-
include Dry::Equalizer(:input, inspect: false)
|
11
|
+
include Dry::Equalizer(:input, inspect: false, immutable: true)
|
12
12
|
|
13
13
|
# @return [Object]
|
14
14
|
attr_reader :input
|
@@ -43,7 +43,7 @@ module Dry
|
|
43
43
|
#
|
44
44
|
# @api public
|
45
45
|
class Failure < Result
|
46
|
-
include Dry::Equalizer(:input, :error, inspect: false)
|
46
|
+
include Dry::Equalizer(:input, :error, inspect: false, immutable: true)
|
47
47
|
|
48
48
|
# @return [#to_s]
|
49
49
|
attr_reader :error
|
data/lib/dry/types/schema/key.rb
CHANGED
@@ -17,7 +17,7 @@ module Dry
|
|
17
17
|
class Key
|
18
18
|
extend ::Dry::Core::Deprecations[:'dry-types']
|
19
19
|
include Type
|
20
|
-
include Dry::Equalizer(:name, :type, :options, inspect: false)
|
20
|
+
include Dry::Equalizer(:name, :type, :options, inspect: false, immutable: true)
|
21
21
|
include Decorator
|
22
22
|
include Builder
|
23
23
|
include Printable
|
@@ -31,6 +31,10 @@ module Dry
|
|
31
31
|
type.meta.fetch(:required) { !type.meta.fetch(:omittable, false) }
|
32
32
|
end
|
33
33
|
|
34
|
+
unless name.is_a?(::Symbol)
|
35
|
+
raise ArgumentError, "Schemas can only contain symbol keys, #{name.inspect} given"
|
36
|
+
end
|
37
|
+
|
34
38
|
super(type, name, required: required, **options)
|
35
39
|
@name = name
|
36
40
|
end
|
data/lib/dry/types/sum.rb
CHANGED
@@ -14,7 +14,7 @@ module Dry
|
|
14
14
|
include Options
|
15
15
|
include Meta
|
16
16
|
include Printable
|
17
|
-
include Dry::Equalizer(:left, :right, :options, :meta, inspect: false)
|
17
|
+
include Dry::Equalizer(:left, :right, :options, :meta, inspect: false, immutable: true)
|
18
18
|
|
19
19
|
# @return [Type]
|
20
20
|
attr_reader :left
|
data/lib/dry/types/version.rb
CHANGED
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.2.
|
4
|
+
version: 1.2.2
|
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-
|
11
|
+
date: 2019-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -64,20 +64,14 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0.
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: 0.2.2
|
67
|
+
version: '0.3'
|
71
68
|
type: :runtime
|
72
69
|
prerelease: false
|
73
70
|
version_requirements: !ruby/object:Gem::Requirement
|
74
71
|
requirements:
|
75
72
|
- - "~>"
|
76
73
|
- !ruby/object:Gem::Version
|
77
|
-
version: '0.
|
78
|
-
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 0.2.2
|
74
|
+
version: '0.3'
|
81
75
|
- !ruby/object:Gem::Dependency
|
82
76
|
name: dry-inflector
|
83
77
|
requirement: !ruby/object:Gem::Requirement
|