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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a22d275ce9f27a5be0edd1ce02714dbf571ee95abab2ab8e127b88e61317ac3
4
- data.tar.gz: 8708d3ceb67ff3a726ae0363fe04fd08da440f3fdf7ae4e2f5632104fdf33810
3
+ metadata.gz: 2b3fc7a2d5685f6e867418934765d0e3a4ecfbc5b62385ee371a38e15c09e9b1
4
+ data.tar.gz: 07ef4d9b60132cf459fbf18709e44b275e23f94141a3dc975d2eb50e7ac500e8
5
5
  SHA512:
6
- metadata.gz: 5ff0c69309f200eef77442aef6e9452046f75394c16b00f0be12cdbad04a8c34a1a02e87e0347fb1875fc0241a83f79e1b70576ad4d4e5202cde40257af3e3bb
7
- data.tar.gz: 6eef147d7238f8ead4f254f37a0f018d5fc932ea3dd87bf334c06c3f0eb4110372078c4dcfad27c80a1dcfe161cc6955942d1daeffda6cd8980f3770b7a3c8b1
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 [our contribution guidelines](https://github.com/rom-rb/rom/blob/master/CONTRIBUTING.md)
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/ci.yml
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.8", "ruby:rc"]
60
+ image: ["jruby:9.2.9", "ruby:rc"]
61
61
  dry_logic_from_master: ["true", "false"]
62
62
  container:
63
63
  image: ${{matrix.image}}
@@ -87,3 +87,6 @@ Naming/MethodName:
87
87
 
88
88
  Style/AsciiComments:
89
89
  Enabled: false
90
+
91
+ Style/DateTime:
92
+ Enabled: false
@@ -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
@@ -12,6 +12,8 @@ group :test do
12
12
  platform :mri do
13
13
  gem 'simplecov', require: false
14
14
  end
15
+
16
+ gem 'dry-struct'
15
17
  end
16
18
 
17
19
  group :tools do
data/README.md CHANGED
@@ -1,21 +1,20 @@
1
1
  [gem]: https://rubygems.org/gems/dry-types
2
- [travis]: https://travis-ci.com/dry-rb/dry-types
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://travis-ci.com/dry-rb/dry-types.svg?branch=master)][travis]
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
- * [Documentation](http://dry-rb.org/gems/dry-types)
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) }
@@ -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.2', '>= 0.2.2'
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
- klass.constructor(cons || block || klass.method(:new))
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
@@ -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
 
@@ -14,7 +14,7 @@ module Dry
14
14
  include Decorator
15
15
  include Builder
16
16
  include Printable
17
- include Dry::Equalizer(:type, :rule, inspect: false)
17
+ include Dry::Equalizer(:type, :rule, inspect: false, immutable: true)
18
18
 
19
19
  # @return [Dry::Logic::Rule]
20
20
  attr_reader :rule
@@ -10,7 +10,7 @@ module Dry
10
10
  #
11
11
  # @api public
12
12
  class Constructor < Nominal
13
- include Dry::Equalizer(:type, :options, inspect: false)
13
+ include Dry::Equalizer(:type, :options, inspect: false, immutable: true)
14
14
 
15
15
  # @return [#call]
16
16
  attr_reader :fn
@@ -146,7 +146,7 @@ module Dry
146
146
  last_arg.equal?(:block)
147
147
  end
148
148
 
149
- include Dry::Equalizer(:fn)
149
+ include Dry::Equalizer(:fn, immutable: true)
150
150
 
151
151
  attr_reader :fn
152
152
 
@@ -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
@@ -9,7 +9,7 @@ module Dry
9
9
  # @api public
10
10
  class Enum
11
11
  include Type
12
- include Dry::Equalizer(:type, :mapping, inspect: false)
12
+ include Dry::Equalizer(:type, :mapping, inspect: false, immutable: true)
13
13
  include Decorator
14
14
  include Builder
15
15
 
@@ -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
@@ -10,7 +10,7 @@ module Dry
10
10
  # @api public
11
11
  class Maybe
12
12
  include Type
13
- include Dry::Equalizer(:type, :options, inspect: false)
13
+ include Dry::Equalizer(:type, :options, inspect: false, immutable: true)
14
14
  include Decorator
15
15
  include Builder
16
16
  include Printable
@@ -13,7 +13,7 @@ module Dry
13
13
  include Decorator
14
14
  include Builder
15
15
  include Printable
16
- include Dry::Equalizer(:type, inspect: false)
16
+ include Dry::Equalizer(:type, inspect: false, immutable: true)
17
17
 
18
18
  undef :options, :constructor
19
19
 
@@ -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
@@ -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
@@ -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
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Types
5
- VERSION = '1.2.1'
5
+ VERSION = '1.2.2'
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.2.1
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-07 00:00:00.000000000 Z
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.2'
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.2'
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