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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b1120eb4914c94c999641d81a01ede2deb790f2
4
- data.tar.gz: 58700f1d2f8d0de68428212b15feba6111de499f
3
+ metadata.gz: 6d195c1fa7087ae24f9994e6f0fd48e00b0714c3
4
+ data.tar.gz: 86e940c3d93ccc1675bd8cbb48d9e7fcfd718eb9
5
5
  SHA512:
6
- metadata.gz: 12003922d8e399f312bb39ebc53c5f37bde3be4a7c5d5d9e3d667fb97358df733810fe096c60c0ca831f9dbcad7ed3b9b8cd81f2017699d12cbe8b950d4bfa05
7
- data.tar.gz: ff1ee72ab2ea48e10458352e82a1d07521f644760107b33f66b67bda5f1067c7dcb77c9fb0d609489a2d278a92c1fe11d139c88d508fe67415a87155fdd5701d
6
+ metadata.gz: 879d57c129b9e8decab5586070ee1572bd75e6ccba749d07c9b5a5efb99406eee522fd3fe66ee72f4fbad0f3a463ba378d0bb9d6d4a2620dfd73498e852529cb
7
+ data.tar.gz: 9245666ea36701273a13bc75d3dc2058ca1261844356210e4830b81bb82f51e921fd374b7a12af4b91f933b77f9d793cb6f4e9cb983664a540e4ad8b29572fe2
@@ -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
@@ -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?(:"visit_#{type}")
22
- send(:"visit_#{type}", args)
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 visit_array(node)
38
- registry['array'].member(call(node))
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'
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Data
3
- VERSION = '0.5.0'.freeze
3
+ VERSION = '0.5.1'.freeze
4
4
  end
5
5
  end
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.0
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