dry-types 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -0
- data/Rakefile +0 -1
- data/lib/dry/types/compiler.rb +10 -0
- data/lib/dry/types/constrained.rb +1 -1
- data/lib/dry/types/constructor.rb +1 -1
- data/lib/dry/types/decorator.rb +0 -5
- data/lib/{spec/dry → dry/types/spec}/types.rb +8 -0
- data/lib/dry/types/sum.rb +18 -0
- data/lib/dry/types/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7886fadf19e4beced5252aba4a5db6b6912804e6
|
4
|
+
data.tar.gz: e305a68af891e5e6c68be0859dcc1866f20d460e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9373b3e8c70db220e865639b9e1080f24c9c8e8c0b6033863ac098af08e5c37d900cd063933402fb42cec26f55a60bf6fcdf2ed846ecaf02572cddf031e25fc8
|
7
|
+
data.tar.gz: b3f2ba541fd524998b71b243e84500a5a290ba1d98ef7d2089e96d34bf0658abed961b2a2ce1a468774c36cdf34ffdb32798fe9cc3403a0e4452741f6d5e3d9a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# v0.12.1 to-be-released
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
|
5
|
+
* `Constructor#try` rescues `ArgumentError` (raised in cases like `Integer('foo')`) (flash-gordon)
|
6
|
+
* `#constructor` works correctly for default and enum types (solnic)
|
7
|
+
* Optional sum types work correctly in `safe` mode (GustavoCaso)
|
8
|
+
* The equalizer of constrained types respects meta (flash-gordon)
|
9
|
+
|
10
|
+
[Compare v0.12.0...master](https://github.com/dry-rb/dry-types/compare/v0.12.0...master)
|
11
|
+
|
1
12
|
# v0.12.0 2017-09-15
|
2
13
|
|
3
14
|
## Added
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/dry/types/compiler.rb
CHANGED
@@ -16,6 +16,11 @@ module Dry
|
|
16
16
|
send(:"visit_#{ type }", body)
|
17
17
|
end
|
18
18
|
|
19
|
+
def visit_constrained(node)
|
20
|
+
definition, rule, meta = node
|
21
|
+
Types::Constrained.new(visit(definition), rule: visit_rule(rule)).meta(meta)
|
22
|
+
end
|
23
|
+
|
19
24
|
def visit_constructor(node)
|
20
25
|
definition, fn_register_name, meta = node
|
21
26
|
fn = Dry::Types::FnContainer[fn_register_name]
|
@@ -38,6 +43,11 @@ module Dry
|
|
38
43
|
end
|
39
44
|
end
|
40
45
|
|
46
|
+
def visit_rule(node)
|
47
|
+
operator, rule = node
|
48
|
+
Dry::Types.rule_compiler.(rule).reduce(operator)
|
49
|
+
end
|
50
|
+
|
41
51
|
def visit_sum(node)
|
42
52
|
*types, meta = node
|
43
53
|
types.map { |type| visit(type) }.reduce(:|).meta(meta)
|
data/lib/dry/types/decorator.rb
CHANGED
@@ -73,4 +73,12 @@ RSpec.shared_examples_for Dry::Types::Definition do
|
|
73
73
|
expect(type.primitive).to be_instance_of(Class)
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
describe '#constructor' do
|
78
|
+
it 'returns a constructor' do
|
79
|
+
constructor = type.constructor(&:to_s)
|
80
|
+
|
81
|
+
expect(constructor).to be_instance_of(Dry::Types::Constructor)
|
82
|
+
end
|
83
|
+
end
|
76
84
|
end
|
data/lib/dry/types/sum.rb
CHANGED
@@ -91,6 +91,24 @@ module Dry
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
def success(input)
|
95
|
+
if left.valid?(input)
|
96
|
+
left.success(input)
|
97
|
+
elsif right.valid?(input)
|
98
|
+
right.success(input)
|
99
|
+
else
|
100
|
+
raise ArgumentError, "Invalid success value '#{input}' for #{inspect}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def failure(input)
|
105
|
+
if !left.valid?(input)
|
106
|
+
left.failure(input, left.try(input).error)
|
107
|
+
else
|
108
|
+
right.failure(input, right.try(input).error)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
94
112
|
# @param [Object] value
|
95
113
|
# @return [Boolean]
|
96
114
|
def primitive?(value)
|
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: 0.12.
|
4
|
+
version: 0.12.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: 2017-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -248,10 +248,10 @@ files:
|
|
248
248
|
- lib/dry/types/options.rb
|
249
249
|
- lib/dry/types/result.rb
|
250
250
|
- lib/dry/types/safe.rb
|
251
|
+
- lib/dry/types/spec/types.rb
|
251
252
|
- lib/dry/types/sum.rb
|
252
253
|
- lib/dry/types/type.rb
|
253
254
|
- lib/dry/types/version.rb
|
254
|
-
- lib/spec/dry/types.rb
|
255
255
|
- log/.gitkeep
|
256
256
|
homepage: https://github.com/dry-rb/dry-types
|
257
257
|
licenses:
|