dry-types 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +378 -206
- data/LICENSE +17 -17
- data/README.md +14 -13
- data/dry-types.gemspec +27 -31
- data/lib/dry/types.rb +7 -11
- data/lib/dry/types/any.rb +2 -2
- data/lib/dry/types/array/member.rb +3 -3
- data/lib/dry/types/builder.rb +5 -1
- data/lib/dry/types/builder_methods.rb +22 -8
- data/lib/dry/types/coercions.rb +6 -0
- data/lib/dry/types/coercions/params.rb +1 -1
- data/lib/dry/types/compiler.rb +2 -2
- data/lib/dry/types/constrained.rb +2 -2
- data/lib/dry/types/constructor.rb +7 -34
- data/lib/dry/types/constructor/function.rb +17 -31
- data/lib/dry/types/core.rb +3 -1
- data/lib/dry/types/decorator.rb +3 -9
- data/lib/dry/types/default.rb +2 -2
- data/lib/dry/types/enum.rb +2 -2
- data/lib/dry/types/errors.rb +5 -5
- data/lib/dry/types/extensions.rb +4 -0
- data/lib/dry/types/extensions/maybe.rb +14 -14
- data/lib/dry/types/extensions/monads.rb +29 -0
- data/lib/dry/types/hash.rb +3 -2
- data/lib/dry/types/lax.rb +2 -5
- data/lib/dry/types/meta.rb +3 -3
- data/lib/dry/types/module.rb +3 -3
- data/lib/dry/types/nominal.rb +1 -1
- data/lib/dry/types/params.rb +6 -0
- data/lib/dry/types/predicate_inferrer.rb +197 -0
- data/lib/dry/types/predicate_registry.rb +34 -0
- data/lib/dry/types/primitive_inferrer.rb +97 -0
- data/lib/dry/types/printer.rb +7 -3
- data/lib/dry/types/result.rb +2 -2
- data/lib/dry/types/schema.rb +23 -2
- data/lib/dry/types/schema/key.rb +16 -3
- data/lib/dry/types/spec/types.rb +14 -1
- data/lib/dry/types/sum.rb +5 -5
- data/lib/dry/types/version.rb +1 -1
- metadata +26 -45
- data/.codeclimate.yml +0 -15
- data/.gitignore +0 -11
- data/.rspec +0 -2
- data/.travis.yml +0 -27
- data/.yardopts +0 -9
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -27
- data/Rakefile +0 -22
- data/benchmarks/hash_schemas.rb +0 -55
- data/benchmarks/lax_schema.rb +0 -15
- data/benchmarks/profile_invalid_input.rb +0 -15
- data/benchmarks/profile_lax_schema_valid.rb +0 -16
- data/benchmarks/profile_valid_input.rb +0 -15
- data/benchmarks/schema_valid_vs_invalid.rb +0 -21
- data/benchmarks/setup.rb +0 -17
data/lib/dry/types/spec/types.rb
CHANGED
@@ -109,7 +109,9 @@ RSpec.shared_examples_for Dry::Types::Nominal do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
RSpec.shared_examples_for 'a constrained type' do |inputs: Object.new|
|
112
|
+
RSpec.shared_examples_for 'a constrained type' do |options = { inputs: Object.new }|
|
113
|
+
inputs = options[:inputs]
|
114
|
+
|
113
115
|
let(:fallback) { Object.new }
|
114
116
|
|
115
117
|
describe '#call' do
|
@@ -137,3 +139,14 @@ RSpec.shared_examples_for 'a nominal type' do |inputs: Object.new|
|
|
137
139
|
end
|
138
140
|
end
|
139
141
|
end
|
142
|
+
|
143
|
+
RSpec.shared_examples_for 'a composable constructor' do
|
144
|
+
describe '#constructor' do
|
145
|
+
it 'has aliases for composition' do
|
146
|
+
expect(type.method(:append)).to eql(type.method(:constructor))
|
147
|
+
expect(type.method(:prepend)).to eql(type.method(:constructor))
|
148
|
+
expect(type.method(:<<)).to eql(type.method(:constructor))
|
149
|
+
expect(type.method(:>>)).to eql(type.method(:constructor))
|
150
|
+
end
|
151
|
+
end
|
152
|
+
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
|
@@ -40,7 +40,7 @@ module Dry
|
|
40
40
|
# @param [Hash] options
|
41
41
|
#
|
42
42
|
# @api private
|
43
|
-
def initialize(left, right, options
|
43
|
+
def initialize(left, right, **options)
|
44
44
|
super
|
45
45
|
@left, @right = left, right
|
46
46
|
freeze
|
@@ -142,11 +142,11 @@ module Dry
|
|
142
142
|
# @see [Meta#meta]
|
143
143
|
#
|
144
144
|
# @api public
|
145
|
-
def meta(data =
|
146
|
-
if
|
145
|
+
def meta(data = Undefined)
|
146
|
+
if Undefined.equal?(data)
|
147
147
|
optional? ? right.meta : super
|
148
148
|
elsif optional?
|
149
|
-
self.class.new(left, right.meta(data), options)
|
149
|
+
self.class.new(left, right.meta(data), **options)
|
150
150
|
else
|
151
151
|
super
|
152
152
|
end
|
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.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-10 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
|
@@ -138,83 +132,67 @@ dependencies:
|
|
138
132
|
requirements:
|
139
133
|
- - "~>"
|
140
134
|
- !ruby/object:Gem::Version
|
141
|
-
version: '0
|
135
|
+
version: '1.0'
|
142
136
|
type: :development
|
143
137
|
prerelease: false
|
144
138
|
version_requirements: !ruby/object:Gem::Requirement
|
145
139
|
requirements:
|
146
140
|
- - "~>"
|
147
141
|
- !ruby/object:Gem::Version
|
148
|
-
version: '0
|
142
|
+
version: '1.0'
|
149
143
|
- !ruby/object:Gem::Dependency
|
150
144
|
name: rake
|
151
145
|
requirement: !ruby/object:Gem::Requirement
|
152
146
|
requirements:
|
153
|
-
- - "
|
147
|
+
- - ">="
|
154
148
|
- !ruby/object:Gem::Version
|
155
|
-
version: '
|
149
|
+
version: '0'
|
156
150
|
type: :development
|
157
151
|
prerelease: false
|
158
152
|
version_requirements: !ruby/object:Gem::Requirement
|
159
153
|
requirements:
|
160
|
-
- - "
|
154
|
+
- - ">="
|
161
155
|
- !ruby/object:Gem::Version
|
162
|
-
version: '
|
156
|
+
version: '0'
|
163
157
|
- !ruby/object:Gem::Dependency
|
164
158
|
name: rspec
|
165
159
|
requirement: !ruby/object:Gem::Requirement
|
166
160
|
requirements:
|
167
|
-
- - "
|
161
|
+
- - ">="
|
168
162
|
- !ruby/object:Gem::Version
|
169
|
-
version: '
|
163
|
+
version: '0'
|
170
164
|
type: :development
|
171
165
|
prerelease: false
|
172
166
|
version_requirements: !ruby/object:Gem::Requirement
|
173
167
|
requirements:
|
174
|
-
- - "
|
168
|
+
- - ">="
|
175
169
|
- !ruby/object:Gem::Version
|
176
|
-
version: '
|
170
|
+
version: '0'
|
177
171
|
- !ruby/object:Gem::Dependency
|
178
172
|
name: yard
|
179
173
|
requirement: !ruby/object:Gem::Requirement
|
180
174
|
requirements:
|
181
|
-
- - "
|
175
|
+
- - ">="
|
182
176
|
- !ruby/object:Gem::Version
|
183
|
-
version: 0
|
177
|
+
version: '0'
|
184
178
|
type: :development
|
185
179
|
prerelease: false
|
186
180
|
version_requirements: !ruby/object:Gem::Requirement
|
187
181
|
requirements:
|
188
|
-
- - "
|
182
|
+
- - ">="
|
189
183
|
- !ruby/object:Gem::Version
|
190
|
-
version: 0
|
184
|
+
version: '0'
|
191
185
|
description: Type system for Ruby supporting coercions, constraints and complex types
|
192
|
-
like structs, value objects, enums etc
|
186
|
+
like structs, value objects, enums etc
|
193
187
|
email:
|
194
188
|
- piotr.solnica@gmail.com
|
195
189
|
executables: []
|
196
190
|
extensions: []
|
197
191
|
extra_rdoc_files: []
|
198
192
|
files:
|
199
|
-
- ".codeclimate.yml"
|
200
|
-
- ".gitignore"
|
201
|
-
- ".rspec"
|
202
|
-
- ".rubocop.yml"
|
203
|
-
- ".travis.yml"
|
204
|
-
- ".yardopts"
|
205
193
|
- CHANGELOG.md
|
206
|
-
- CONTRIBUTING.md
|
207
|
-
- Gemfile
|
208
194
|
- LICENSE
|
209
195
|
- README.md
|
210
|
-
- Rakefile
|
211
|
-
- benchmarks/hash_schemas.rb
|
212
|
-
- benchmarks/lax_schema.rb
|
213
|
-
- benchmarks/profile_invalid_input.rb
|
214
|
-
- benchmarks/profile_lax_schema_valid.rb
|
215
|
-
- benchmarks/profile_valid_input.rb
|
216
|
-
- benchmarks/schema_valid_vs_invalid.rb
|
217
|
-
- benchmarks/setup.rb
|
218
196
|
- dry-types.gemspec
|
219
197
|
- lib/dry-types.rb
|
220
198
|
- lib/dry/types.rb
|
@@ -242,6 +220,7 @@ files:
|
|
242
220
|
- lib/dry/types/errors.rb
|
243
221
|
- lib/dry/types/extensions.rb
|
244
222
|
- lib/dry/types/extensions/maybe.rb
|
223
|
+
- lib/dry/types/extensions/monads.rb
|
245
224
|
- lib/dry/types/fn_container.rb
|
246
225
|
- lib/dry/types/hash.rb
|
247
226
|
- lib/dry/types/hash/constructor.rb
|
@@ -254,6 +233,9 @@ files:
|
|
254
233
|
- lib/dry/types/nominal.rb
|
255
234
|
- lib/dry/types/options.rb
|
256
235
|
- lib/dry/types/params.rb
|
236
|
+
- lib/dry/types/predicate_inferrer.rb
|
237
|
+
- lib/dry/types/predicate_registry.rb
|
238
|
+
- lib/dry/types/primitive_inferrer.rb
|
257
239
|
- lib/dry/types/printable.rb
|
258
240
|
- lib/dry/types/printer.rb
|
259
241
|
- lib/dry/types/result.rb
|
@@ -263,8 +245,7 @@ files:
|
|
263
245
|
- lib/dry/types/sum.rb
|
264
246
|
- lib/dry/types/type.rb
|
265
247
|
- lib/dry/types/version.rb
|
266
|
-
-
|
267
|
-
homepage: https://github.com/dry-rb/dry-types
|
248
|
+
homepage: https://dry-rb.org/gems/dry-types
|
268
249
|
licenses:
|
269
250
|
- MIT
|
270
251
|
metadata:
|
@@ -291,5 +272,5 @@ rubygems_version: 3.0.3
|
|
291
272
|
signing_key:
|
292
273
|
specification_version: 4
|
293
274
|
summary: Type system for Ruby supporting coercions, constraints and complex types
|
294
|
-
like structs, value objects, enums etc
|
275
|
+
like structs, value objects, enums etc
|
295
276
|
test_files: []
|
data/.codeclimate.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
version: "2"
|
2
|
-
|
3
|
-
prepare:
|
4
|
-
fetch:
|
5
|
-
- url: "https://raw.githubusercontent.com/dry-rb/devtools/master/.rubocop.yml"
|
6
|
-
path: ".rubocop.yml"
|
7
|
-
|
8
|
-
exclude_patterns:
|
9
|
-
- "benchmarks/"
|
10
|
-
- "examples/"
|
11
|
-
- "spec/"
|
12
|
-
|
13
|
-
plugins:
|
14
|
-
rubocop:
|
15
|
-
enabled: true
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
bundler_args: --without benchmarks tools
|
4
|
-
before_script:
|
5
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
6
|
-
- chmod +x ./cc-test-reporter
|
7
|
-
- ./cc-test-reporter before-build
|
8
|
-
after_script:
|
9
|
-
- "[ -d coverage ] && ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
10
|
-
script:
|
11
|
-
- bundle exec rake
|
12
|
-
rvm:
|
13
|
-
- 2.6.3
|
14
|
-
- 2.5.5
|
15
|
-
- 2.4.6
|
16
|
-
- jruby-9.2.7.0
|
17
|
-
env:
|
18
|
-
global:
|
19
|
-
- COVERAGE=true
|
20
|
-
notifications:
|
21
|
-
email: false
|
22
|
-
webhooks:
|
23
|
-
urls:
|
24
|
-
- https://webhooks.gitter.im/e/19098b4253a72c9796db
|
25
|
-
on_success: change # options: [always|never|change] default: always
|
26
|
-
on_failure: always # options: [always|never|change] default: always
|
27
|
-
on_start: false # default: false
|
data/.yardopts
DELETED
data/CONTRIBUTING.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Issue Guidelines
|
2
|
-
|
3
|
-
## Reporting bugs
|
4
|
-
|
5
|
-
If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
|
6
|
-
|
7
|
-
## Reporting feature requests
|
8
|
-
|
9
|
-
Report a feature request **only after discussing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
|
10
|
-
|
11
|
-
## Reporting questions, support requests, ideas, concerns etc.
|
12
|
-
|
13
|
-
**PLEASE DON'T** - use [discourse.dry-rb.org](https://discourse.dry-rb.org) instead.
|
14
|
-
|
15
|
-
# Pull Request Guidelines
|
16
|
-
|
17
|
-
A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
|
18
|
-
|
19
|
-
Other requirements:
|
20
|
-
|
21
|
-
1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
|
22
|
-
2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
|
23
|
-
3) Add API documentation if it's a new feature
|
24
|
-
4) Update API documentation if it changes an existing feature
|
25
|
-
5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
|
26
|
-
|
27
|
-
# Asking for help
|
28
|
-
|
29
|
-
If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org).
|
data/Gemfile
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
-
|
7
|
-
gemspec
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
platform :mri do
|
11
|
-
gem 'simplecov', require: false
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
group :tools do
|
16
|
-
gem 'pry-byebug', platform: :mri
|
17
|
-
gem 'rubocop'
|
18
|
-
end
|
19
|
-
|
20
|
-
group :benchmarks do
|
21
|
-
gem 'attrio'
|
22
|
-
gem 'benchmark-ips'
|
23
|
-
gem 'dry-struct'
|
24
|
-
gem 'fast_attributes'
|
25
|
-
gem 'hotch'
|
26
|
-
gem 'virtus'
|
27
|
-
end
|
data/Rakefile
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/gem_tasks'
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
task :run_specs do
|
7
|
-
require 'rspec/core'
|
8
|
-
|
9
|
-
types_result = RSpec::Core::Runner.run(['spec/dry'])
|
10
|
-
RSpec.clear_examples
|
11
|
-
|
12
|
-
Dry::Types.load_extensions(:maybe)
|
13
|
-
ext_result = RSpec::Core::Runner.run(['spec'])
|
14
|
-
|
15
|
-
exit [types_result, ext_result].max
|
16
|
-
end
|
17
|
-
|
18
|
-
task default: :run_specs
|
19
|
-
|
20
|
-
require 'yard'
|
21
|
-
require 'yard/rake/yardoc_task'
|
22
|
-
YARD::Rake::YardocTask.new(:doc)
|
data/benchmarks/hash_schemas.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift('lib')
|
4
|
-
|
5
|
-
require 'bundler/setup'
|
6
|
-
require 'dry-types'
|
7
|
-
|
8
|
-
module SchemaBench
|
9
|
-
def self.hash_schema(type)
|
10
|
-
Dry::Types['nominal.hash'].public_send(
|
11
|
-
type,
|
12
|
-
email: Dry::Types['nominal.string'],
|
13
|
-
age: Dry::Types['params.integer'],
|
14
|
-
admin: Dry::Types['params.bool'],
|
15
|
-
address: Dry::Types['nominal.hash'].public_send(
|
16
|
-
type,
|
17
|
-
city: Dry::Types['nominal.string'],
|
18
|
-
street: Dry::Types['nominal.string']
|
19
|
-
)
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
private_class_method(:hash_schema)
|
24
|
-
|
25
|
-
SCHEMAS =
|
26
|
-
Dry::Types::Hash
|
27
|
-
.public_instance_methods(false)
|
28
|
-
.map { |schema_type| [schema_type, hash_schema(schema_type)] }
|
29
|
-
.to_h
|
30
|
-
|
31
|
-
INPUT = {
|
32
|
-
email: 'jane@doe.org',
|
33
|
-
age: '20',
|
34
|
-
admin: '1',
|
35
|
-
address: { city: 'NYC', street: 'Street 1/2' }
|
36
|
-
}.freeze
|
37
|
-
end
|
38
|
-
|
39
|
-
require 'benchmark/ips'
|
40
|
-
|
41
|
-
Benchmark.ips do |x|
|
42
|
-
SchemaBench::SCHEMAS.each do |schema_type, schema|
|
43
|
-
x.report("#{schema_type}#call") do
|
44
|
-
schema.call(SchemaBench::INPUT)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
SchemaBench::SCHEMAS.each do |schema_type, schema|
|
49
|
-
x.report("#{schema_type}#try") do
|
50
|
-
schema.try(SchemaBench::INPUT)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
x.compare!
|
55
|
-
end
|