dry-data 0.5.0 → 0.5.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 +10 -0
- data/lib/dry/data/compiler.rb +14 -4
- data/lib/dry/data/safe.rb +19 -0
- data/lib/dry/data/type_builder.rb +5 -0
- data/lib/dry/data/types/form.rb +8 -0
- data/lib/dry/data/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d195c1fa7087ae24f9994e6f0fd48e00b0714c3
|
4
|
+
data.tar.gz: 86e940c3d93ccc1675bd8cbb48d9e7fcfd718eb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 879d57c129b9e8decab5586070ee1572bd75e6ccba749d07c9b5a5efb99406eee522fd3fe66ee72f4fbad0f3a463ba378d0bb9d6d4a2620dfd73498e852529cb
|
7
|
+
data.tar.gz: 9245666ea36701273a13bc75d3dc2058ca1261844356210e4830b81bb82f51e921fd374b7a12af4b91f933b77f9d793cb6f4e9cb983664a540e4ad8b29572fe2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# v0.5.1 2016-01-11
|
2
|
+
|
3
|
+
## Added
|
4
|
+
|
5
|
+
* `Dry::Data::Type#safe` for types which can skip constructor when primitive does
|
6
|
+
not match input's class (solnic)
|
7
|
+
* `form.array` and `form.hash` safe types (solnic)
|
8
|
+
|
9
|
+
[Compare v0.5.0...v0.5.1](https://github.com/dryrb/dry-data/compare/v0.5.0...v0.5.1)
|
10
|
+
|
1
11
|
# v0.5.0 2016-01-11
|
2
12
|
|
3
13
|
## Added
|
data/lib/dry/data/compiler.rb
CHANGED
@@ -17,9 +17,10 @@ module Dry
|
|
17
17
|
|
18
18
|
def visit_type(node)
|
19
19
|
type, args = node
|
20
|
+
meth = :"visit_#{type.gsub('.', '_')}"
|
20
21
|
|
21
|
-
if respond_to?(
|
22
|
-
send(
|
22
|
+
if respond_to?(meth)
|
23
|
+
send(meth, args)
|
23
24
|
else
|
24
25
|
registry[type]
|
25
26
|
end
|
@@ -29,13 +30,22 @@ module Dry
|
|
29
30
|
node.map { |type| visit(type) }.reduce(:|)
|
30
31
|
end
|
31
32
|
|
33
|
+
def visit_array(node)
|
34
|
+
registry['array'].member(call(node))
|
35
|
+
end
|
36
|
+
|
37
|
+
def visit_form_array(node)
|
38
|
+
registry['form.array'].member(call(node))
|
39
|
+
end
|
40
|
+
|
32
41
|
def visit_hash(node)
|
33
42
|
constructor, schema = node
|
34
43
|
registry['hash'].public_send(constructor, schema.map { |key| visit(key) }.reduce(:merge))
|
35
44
|
end
|
36
45
|
|
37
|
-
def
|
38
|
-
|
46
|
+
def visit_form_hash(node)
|
47
|
+
constructor, schema = node
|
48
|
+
registry['form.hash'].public_send(constructor, schema.map { |key| visit(key) }.reduce(:merge))
|
39
49
|
end
|
40
50
|
|
41
51
|
def visit_key(node)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'dry/data/decorator'
|
2
|
+
|
3
|
+
module Dry
|
4
|
+
module Data
|
5
|
+
class Safe
|
6
|
+
include Decorator
|
7
|
+
include TypeBuilder
|
8
|
+
|
9
|
+
def call(input)
|
10
|
+
if input.is_a?(primitive)
|
11
|
+
type.call(input)
|
12
|
+
else
|
13
|
+
input
|
14
|
+
end
|
15
|
+
end
|
16
|
+
alias_method :[], :call
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -20,6 +20,10 @@ module Dry
|
|
20
20
|
def enum(*values)
|
21
21
|
Enum.new(constrained(inclusion: values), values: values)
|
22
22
|
end
|
23
|
+
|
24
|
+
def safe
|
25
|
+
Safe.new(self)
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -28,4 +32,5 @@ require 'dry/data/default'
|
|
28
32
|
require 'dry/data/constrained'
|
29
33
|
require 'dry/data/enum'
|
30
34
|
require 'dry/data/optional'
|
35
|
+
require 'dry/data/safe'
|
31
36
|
require 'dry/data/sum_type'
|
data/lib/dry/data/types/form.rb
CHANGED
@@ -41,5 +41,13 @@ module Dry
|
|
41
41
|
register('form.decimal') do
|
42
42
|
Type.new(Coercions::Form.method(:to_decimal), primitive: BigDecimal)
|
43
43
|
end
|
44
|
+
|
45
|
+
register('form.array') do
|
46
|
+
self['array'].safe
|
47
|
+
end
|
48
|
+
|
49
|
+
register('form.hash') do
|
50
|
+
self['hash'].safe
|
51
|
+
end
|
44
52
|
end
|
45
53
|
end
|
data/lib/dry/data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/dry/data/default.rb
|
188
188
|
- lib/dry/data/enum.rb
|
189
189
|
- lib/dry/data/optional.rb
|
190
|
+
- lib/dry/data/safe.rb
|
190
191
|
- lib/dry/data/struct.rb
|
191
192
|
- lib/dry/data/sum_type.rb
|
192
193
|
- lib/dry/data/type.rb
|