rasti-types 1.1.1 → 1.1.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: d0bac405f0360768d8bc4d80aae59ab53fba2cb4251102c673cc20d438e031a1
4
- data.tar.gz: 29fac9e64d7f601f50cba845e5b9852a261c8df676c5d41b02d35a1b10e6559a
3
+ metadata.gz: 668b604d95b67bb965b9860363c9708e7588ffdf4c2db16f82d7c4ec1c08e4bd
4
+ data.tar.gz: 98f6a227331dae03e77d45813d40d34db1bef7e30c8724dd7a43c5f20369acd6
5
5
  SHA512:
6
- metadata.gz: c265eafe733a9741241c452690ee0ac48d22f5e2c30b10dd4c0f6a3eec7cc62d14fe5a38fd4ebf0764b953007d3c9065201e66e8cb122be311bc1d5b09cdf992
7
- data.tar.gz: 115cd63203d805bdd201c64a23e90d367d32b1e03ea11fc1fd8c705e5daf40386e2bb13e8dd45e2fd35f572124e1129761e74d2e8e03ecca88fef5b438896622
6
+ metadata.gz: 68255142316b26b850774f6bf07303f481a648d5ab81596685d4c15aee681bd1d5825867d0bc8c5168268f7eed9d431720f29393cd1e0d29fc0d278db8290f08
7
+ data.tar.gz: 419d07e23e42296eac48d707d556cab894c7fccf4690caea1d79b77a7b27c99e2b897a90e80b34d55fea881578570e0200d3f156c106c57ca9303eeff618101e
@@ -22,11 +22,11 @@ module Rasti
22
22
  end
23
23
 
24
24
  def valid?(value)
25
- value.is_a? ::Hash
25
+ value.is_a?(::Hash) || value.is_a?(model)
26
26
  end
27
27
 
28
28
  def transform(value)
29
- model.new value
29
+ value.is_a?(model) ? value : model.new(value)
30
30
  end
31
31
 
32
32
  end
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  module Types
3
- VERSION = '1.1.1'
3
+ VERSION = '1.1.2'
4
4
  end
5
5
  end
data/spec/model_spec.rb CHANGED
@@ -2,13 +2,19 @@ require 'minitest_helper'
2
2
 
3
3
  describe Rasti::Types::Model do
4
4
 
5
- it 'Class' do
5
+ it 'Hash' do
6
6
  result = Rasti::Types::Model[Point].cast x: 1, y: 2
7
7
  result.must_be_instance_of Point
8
8
  result.x.must_equal 1
9
9
  result.y.must_equal 2
10
10
  end
11
11
 
12
+ it 'Model' do
13
+ model = Point.new x: 3, y: 4
14
+ result = Rasti::Types::Model[Point].cast model
15
+ result.must_equal model
16
+ end
17
+
12
18
  it 'Hash -> CastError' do
13
19
  error = proc { Rasti::Types::Model[Point].cast(z: 'text') }.must_raise Rasti::Types::CompoundError
14
20
  error.message.must_equal "Errors:\n- x: [\"not present\"]\n- y: [\"not present\"]"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rasti-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_require