ree_lib 1.0.15 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper.rb +7 -6
  4. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/abstract_type.rb +4 -4
  5. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb +20 -20
  6. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/bool.rb +12 -12
  7. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date.rb +13 -13
  8. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date_time.rb +13 -13
  9. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/float.rb +13 -13
  10. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/integer.rb +13 -13
  11. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/string.rb +12 -12
  12. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/time.rb +13 -13
  13. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/array_spec.rb +15 -6
  14. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/bool_spec.rb +9 -9
  15. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_spec.rb +11 -11
  16. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_time_spec.rb +17 -17
  17. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/float_spec.rb +14 -14
  18. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/hash_spec.rb +5 -1
  19. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/integer_spec.rb +15 -15
  20. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/string_spec.rb +13 -13
  21. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/time_spec.rb +17 -17
  22. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/type_options_spec.rb +2 -2
  23. data/lib/ree_lib/version.rb +1 -1
  24. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a15d911dfb9f1955ac1829941bdb259c1423867dabb407221a1d55232dde3e50
4
- data.tar.gz: b76069a3bd3760240ea5232de630f7ff4b372a767b5098ed9a91d7e224f73f7c
3
+ metadata.gz: 6160f2952d35b381ccb85c48139a84187d975ec72297a13ba240656398610bb1
4
+ data.tar.gz: d8aa690997677ddf8ae5bf2f219b00e5d7cad9bb0dcea89905f496bca2389072
5
5
  SHA512:
6
- metadata.gz: 39b0b379f130624a30c254bc569d3cf8a3942974d036b4bebfc37d1a9c2087917644d61e946b7471b97102b832c43c951d8c209d1f64d9d2d7198b18082f0eed
7
- data.tar.gz: 4628fd0c89f2a3670dfb7895decc76aae447057e5d7b0b3591c4942ca1be910b50653d41089589a29a48d794c703921232b4776266721982b30fd78881515ade
6
+ metadata.gz: 666753ee3a5ff1057d1d8b371d84b9a2510b0d89ce4a259ded6bdf0466f61f0009c18505f70bee8e92e65058cc1d460510cf9121ee3980845c3fd05936aa1f1f
7
+ data.tar.gz: d543b184c95e126f6623e339dcfe17d6966aa19b50c19378701f250d45f599b4734f2bf0c0a194effb4af0bd194b88d244060076362e7e569215b1470cee0275
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.15)
4
+ ree_lib (1.0.17)
5
5
  binding_of_caller (~> 1.0.0)
6
6
  i18n (~> 1.12.0)
7
7
  loofah (~> 2.18.0)
@@ -19,32 +19,33 @@ class ReeMapper::Mapper
19
19
 
20
20
  if type
21
21
  class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
22
- def #{method}(obj, role: nil)
23
- @type.#{method}(obj, role: role)
22
+ def #{method}(obj, name: nil, role: nil)
23
+ @type.#{method}(obj, name: name, role: role)
24
24
  end
25
25
  RUBY
26
26
  else
27
27
  class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
28
- def #{method}(obj, role: nil)
28
+ def #{method}(obj, name: nil, role: nil)
29
29
  @fields.each_with_object(@#{method}_strategy.build_object) do |(_, field), acc|
30
30
  next unless field.has_role?(role)
31
+ nested_name = name ? "\#{name}[\#{field.name_as_str}]" : field.name_as_str
31
32
 
32
33
  if @#{method}_strategy.has_value?(obj, field)
33
34
  value = @#{method}_strategy.get_value(obj, field)
34
35
  unless value.nil? && field.null
35
- value = field.type.public_send(:#{method}, value, role: role)
36
+ value = field.type.#{method}(value, name: nested_name, role: role)
36
37
  end
37
38
  @#{method}_strategy.assign_value(acc, field, value)
38
39
  elsif field.optional || @#{method}_strategy.always_optional
39
40
  if field.has_default?
40
41
  value = field.default
41
42
  unless value.nil? && field.null
42
- value = field.type.public_send(:#{method}, value, role: role)
43
+ value = field.type.#{method}(value, name: nested_name, role: role)
43
44
  end
44
45
  @#{method}_strategy.assign_value(acc, field, value)
45
46
  end
46
47
  else
47
- raise ReeMapper::TypeError, "Missing required field `\#{field.from}`"
48
+ raise ReeMapper::TypeError, "Missing required field `\#{field.from_as_str}` for `\#{name || 'root'}`"
48
49
  end
49
50
  end
50
51
  end
@@ -1,17 +1,17 @@
1
1
  class ReeMapper::AbstractType
2
- def serialize(value, role: nil)
2
+ def serialize(value, name:, role: nil)
3
3
  raise NotImplementedError
4
4
  end
5
5
 
6
- def cast(value, role: nil)
6
+ def cast(value, name:, role: nil)
7
7
  raise NotImplementedError
8
8
  end
9
9
 
10
- def db_dump(value, role: nil)
10
+ def db_dump(value, name:, role: nil)
11
11
  raise NotImplementedError
12
12
  end
13
13
 
14
- def db_load(value, role: nil)
14
+ def db_load(value, name:, role: nil)
15
15
  raise NotImplementedError
16
16
  end
17
17
  end
@@ -8,63 +8,63 @@ class ReeMapper::Array < ReeMapper::AbstractType
8
8
  @of = of
9
9
  end
10
10
 
11
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
12
- def serialize(value, role: nil)
11
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
12
+ def serialize(value, name:, role: nil)
13
13
  if value.is_a?(Array)
14
- value.map {
14
+ value.map.with_index {
15
15
  if _1.nil? && of.null
16
16
  _1
17
17
  else
18
- of.type.serialize(_1, role: role)
18
+ of.type.serialize(_1, name: "#{name}[#{_2}]", role: role)
19
19
  end
20
20
  }
21
21
  else
22
- raise ReeMapper::TypeError, 'should be an array'
22
+ raise ReeMapper::TypeError, "`#{name}` should be an array"
23
23
  end
24
24
  end
25
25
 
26
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
27
- def cast(value, role: nil)
26
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
27
+ def cast(value, name:, role: nil)
28
28
  if value.is_a?(Array)
29
- value.map {
29
+ value.map.with_index {
30
30
  if _1.nil? && of.null
31
31
  _1
32
32
  else
33
- of.type.cast(_1, role: role)
33
+ of.type.cast(_1, name: "#{name}[#{_2}]", role: role)
34
34
  end
35
35
  }
36
36
  else
37
- raise ReeMapper::TypeError, "should be an array"
37
+ raise ReeMapper::TypeError, "`#{name}` should be an array"
38
38
  end
39
39
  end
40
40
 
41
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
42
- def db_dump(value, role: nil)
41
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
42
+ def db_dump(value, name:, role: nil)
43
43
  if value.is_a?(Array)
44
- value.map {
44
+ value.map.with_index {
45
45
  if _1.nil? && of.null
46
46
  _1
47
47
  else
48
- of.type.db_dump(_1, role: role)
48
+ of.type.db_dump(_1, name: "#{name}[#{_2}]", role: role)
49
49
  end
50
50
  }
51
51
  else
52
- raise ReeMapper::TypeError, 'should be an array'
52
+ raise ReeMapper::TypeError, "`#{name}` should be an array"
53
53
  end
54
54
  end
55
55
 
56
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
57
- def db_load(value, role: nil)
56
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
57
+ def db_load(value, name:, role: nil)
58
58
  if value.is_a?(Array)
59
- value.map {
59
+ value.map.with_index {
60
60
  if _1.nil? && of.null
61
61
  _1
62
62
  else
63
- of.type.db_load(_1, role: role)
63
+ of.type.db_load(_1, name: "#{name}[#{_2}]", role: role)
64
64
  end
65
65
  }
66
66
  else
67
- raise ReeMapper::TypeError, "should be an array"
67
+ raise ReeMapper::TypeError, "`#{name}` should be an array"
68
68
  end
69
69
  end
70
70
  end
@@ -4,33 +4,33 @@ class ReeMapper::Bool < ReeMapper::AbstractType
4
4
  TRUE_CAST_VALUES = ['1', 'true', 'on', 1, true].freeze
5
5
  FALSE_CAST_VALUES = ['0', 'false', 'off', 0, false].freeze
6
6
 
7
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Bool).throws(ReeMapper::TypeError)
8
- def serialize(value, role: nil)
7
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Bool).throws(ReeMapper::TypeError)
8
+ def serialize(value, name:, role: nil)
9
9
  if value.is_a?(TrueClass) || value.is_a?(FalseClass)
10
10
  value
11
11
  else
12
- raise ReeMapper::TypeError, 'should be a boolean'
12
+ raise ReeMapper::TypeError, "`#{name}` should be a boolean"
13
13
  end
14
14
  end
15
15
 
16
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Bool).throws(ReeMapper::CoercionError)
17
- def cast(value, role: nil)
16
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Bool).throws(ReeMapper::CoercionError)
17
+ def cast(value, name:, role: nil)
18
18
  if TRUE_CAST_VALUES.include?(value)
19
19
  true
20
20
  elsif FALSE_CAST_VALUES.include?(value)
21
21
  false
22
22
  else
23
- raise ReeMapper::CoercionError, "should be a boolean"
23
+ raise ReeMapper::CoercionError, "`#{name}` is invalid boolean"
24
24
  end
25
25
  end
26
26
 
27
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Bool).throws(ReeMapper::TypeError)
28
- def db_dump(value, role: nil)
29
- serialize(value, role: role)
27
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Bool).throws(ReeMapper::TypeError)
28
+ def db_dump(value, name:, role: nil)
29
+ serialize(value, name: name, role: role)
30
30
  end
31
31
 
32
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Bool).throws(ReeMapper::CoercionError)
33
- def db_load(value, role: nil)
34
- cast(value, role: role)
32
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Bool).throws(ReeMapper::CoercionError)
33
+ def db_load(value, name:, role: nil)
34
+ cast(value, name: name, role: role)
35
35
  end
36
36
  end
@@ -3,17 +3,17 @@
3
3
  require 'date'
4
4
 
5
5
  class ReeMapper::Date < ReeMapper::AbstractType
6
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Date).throws(ReeMapper::TypeError)
7
- def serialize(value, role: nil)
6
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Date).throws(ReeMapper::TypeError)
7
+ def serialize(value, name:, role: nil)
8
8
  if value.class == Date
9
9
  value
10
10
  else
11
- raise ReeMapper::TypeError, "should be a date"
11
+ raise ReeMapper::TypeError, "`#{name}` should be a date"
12
12
  end
13
13
  end
14
14
 
15
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Date).throws(ReeMapper::TypeError, ReeMapper::CoercionError)
16
- def cast(value, role: nil)
15
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Date).throws(ReeMapper::TypeError, ReeMapper::CoercionError)
16
+ def cast(value, name:, role: nil)
17
17
  if value.class == Date
18
18
  value
19
19
  elsif value.class == DateTime || value.class == Time
@@ -22,20 +22,20 @@ class ReeMapper::Date < ReeMapper::AbstractType
22
22
  begin
23
23
  Date.parse(value)
24
24
  rescue ArgumentError => e
25
- raise ReeMapper::CoercionError, "is invalid date"
25
+ raise ReeMapper::CoercionError, "`#{name}` is invalid date"
26
26
  end
27
27
  else
28
- raise ReeMapper::TypeError, "should be a date"
28
+ raise ReeMapper::TypeError, "`#{name}` should be a date"
29
29
  end
30
30
  end
31
31
 
32
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Date).throws(ReeMapper::TypeError)
33
- def db_dump(value, role: nil)
34
- serialize(value, role: role)
32
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Date).throws(ReeMapper::TypeError)
33
+ def db_dump(value, name:, role: nil)
34
+ serialize(value, name: name, role: role)
35
35
  end
36
36
 
37
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Date).throws(ReeMapper::TypeError, ReeMapper::CoercionError)
38
- def db_load(value, role: nil)
39
- cast(value, role: role)
37
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Date).throws(ReeMapper::TypeError, ReeMapper::CoercionError)
38
+ def db_load(value, name:, role: nil)
39
+ cast(value, name: name, role: role)
40
40
  end
41
41
  end
@@ -3,17 +3,17 @@
3
3
  require 'date'
4
4
 
5
5
  class ReeMapper::DateTime < ReeMapper::AbstractType
6
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => DateTime).throws(ReeMapper::TypeError)
7
- def serialize(value, role: nil)
6
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => DateTime).throws(ReeMapper::TypeError)
7
+ def serialize(value, name:, role: nil)
8
8
  if value.class == DateTime
9
9
  value
10
10
  else
11
- raise ReeMapper::TypeError, "should be a datetime"
11
+ raise ReeMapper::TypeError, "`#{name}` should be a datetime"
12
12
  end
13
13
  end
14
14
 
15
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => DateTime).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
16
- def cast(value, role: nil)
15
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => DateTime).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
16
+ def cast(value, name:, role: nil)
17
17
  if value.class == DateTime
18
18
  value
19
19
  elsif value.class == Time
@@ -22,20 +22,20 @@ class ReeMapper::DateTime < ReeMapper::AbstractType
22
22
  begin
23
23
  ReeDatetime::InDefaultTimeZone.new.call(DateTime.parse(value))
24
24
  rescue ArgumentError
25
- raise ReeMapper::CoercionError, "is invalid datetime"
25
+ raise ReeMapper::CoercionError, "`#{name}` is invalid datetime"
26
26
  end
27
27
  else
28
- raise ReeMapper::TypeError, "should be a datetime"
28
+ raise ReeMapper::TypeError, "`#{name}` should be a datetime"
29
29
  end
30
30
  end
31
31
 
32
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => DateTime).throws(ReeMapper::TypeError)
33
- def db_dump(value, role: nil)
34
- serialize(value, role: role)
32
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => DateTime).throws(ReeMapper::TypeError)
33
+ def db_dump(value, name:, role: nil)
34
+ serialize(value, name: name, role: role)
35
35
  end
36
36
 
37
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => DateTime).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
38
- def db_load(value, role: nil)
39
- cast(value, role: role)
37
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => DateTime).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
38
+ def db_load(value, name:, role: nil)
39
+ cast(value, name: name, role: role)
40
40
  end
41
41
  end
@@ -1,37 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ReeMapper::Float < ReeMapper::AbstractType
4
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::TypeError)
5
- def serialize(value, role: nil)
4
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::TypeError)
5
+ def serialize(value, name:, role: nil)
6
6
  if value.is_a?(Float)
7
7
  value
8
8
  else
9
- raise ReeMapper::TypeError, 'should be a float'
9
+ raise ReeMapper::TypeError, "`#{name}` should be a float"
10
10
  end
11
11
  end
12
12
 
13
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
14
- def cast(value, role: nil)
13
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
14
+ def cast(value, name:, role: nil)
15
15
  if value.is_a?(Float)
16
16
  value
17
17
  elsif value.is_a?(String)
18
18
  begin
19
19
  Float(value)
20
20
  rescue ArgumentError => e
21
- raise ReeMapper::CoercionError, "is invalid float"
21
+ raise ReeMapper::CoercionError, "`#{name}` is invalid float"
22
22
  end
23
23
  else
24
- raise ReeMapper::TypeError, "should be a float"
24
+ raise ReeMapper::TypeError, "`#{name}` should be a float"
25
25
  end
26
26
  end
27
27
 
28
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::CoercionError)
29
- def db_dump(value, role: nil)
30
- serialize(value, role: role)
28
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::CoercionError)
29
+ def db_dump(value, name:, role: nil)
30
+ serialize(value, name: name, role: role)
31
31
  end
32
32
 
33
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
34
- def db_load(value, role: nil)
35
- cast(value, role: role)
33
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
34
+ def db_load(value, name:, role: nil)
35
+ cast(value, name: name, role: role)
36
36
  end
37
37
  end
@@ -1,37 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ReeMapper::Integer < ReeMapper::AbstractType
4
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Integer).throws(ReeMapper::TypeError)
5
- def serialize(value, role: nil)
4
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Integer).throws(ReeMapper::TypeError)
5
+ def serialize(value, name:, role: nil)
6
6
  if value.is_a? Integer
7
7
  value
8
8
  else
9
- raise ReeMapper::TypeError, 'should be an integer'
9
+ raise ReeMapper::TypeError, "`#{name}` should be an integer"
10
10
  end
11
11
  end
12
12
 
13
- contract(Any , Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]]=> Integer).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
14
- def cast(value, role: nil)
13
+ contract(Any , Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]]=> Integer).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
14
+ def cast(value, name:, role: nil)
15
15
  if value.is_a?(Integer)
16
16
  value
17
17
  elsif value.is_a?(String)
18
18
  begin
19
19
  Integer(value)
20
20
  rescue ArgumentError => e
21
- raise ReeMapper::CoercionError, "is invalid integer"
21
+ raise ReeMapper::CoercionError, "`#{name}` is invalid integer"
22
22
  end
23
23
  else
24
- raise ReeMapper::TypeError, "should be an integer"
24
+ raise ReeMapper::TypeError, "`#{name}` should be an integer"
25
25
  end
26
26
  end
27
27
 
28
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Integer).throws(ReeMapper::TypeError)
29
- def db_dump(value, role: nil)
30
- serialize(value, role: role)
28
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Integer).throws(ReeMapper::TypeError)
29
+ def db_dump(value, name:, role: nil)
30
+ serialize(value, name: name, role: role)
31
31
  end
32
32
 
33
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Integer).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
34
- def db_load(value, role: nil)
35
- cast(value, role: role)
33
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Integer).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
34
+ def db_load(value, name:, role: nil)
35
+ cast(value, name: name, role: role)
36
36
  end
37
37
  end
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ReeMapper::String < ReeMapper::AbstractType
4
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
5
- def serialize(value, role: nil)
4
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
5
+ def serialize(value, name:, role: nil)
6
6
  if value.is_a? String
7
7
  value
8
8
  else
9
- raise ReeMapper::TypeError, 'should be a string'
9
+ raise ReeMapper::TypeError, "`#{name}` should be a string"
10
10
  end
11
11
  end
12
12
 
13
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
14
- def cast(value, role: nil)
15
- serialize(value, role: role)
13
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
14
+ def cast(value, name:, role: nil)
15
+ serialize(value, name: name, role: role)
16
16
  end
17
17
 
18
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
19
- def db_dump(value, role: nil)
20
- serialize(value, role: role)
18
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
19
+ def db_dump(value, name:, role: nil)
20
+ serialize(value, name: name, role: role)
21
21
  end
22
22
 
23
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
24
- def db_load(value, role: nil)
25
- serialize(value, role: role)
23
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
24
+ def db_load(value, name:, role: nil)
25
+ serialize(value, name: name, role: role)
26
26
  end
27
27
  end
@@ -3,17 +3,17 @@
3
3
  require 'time'
4
4
 
5
5
  class ReeMapper::Time < ReeMapper::AbstractType
6
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Time).throws(ReeMapper::TypeError)
7
- def serialize(value, role: nil)
6
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Time).throws(ReeMapper::TypeError)
7
+ def serialize(value, name:, role: nil)
8
8
  if value.class == Time
9
9
  value
10
10
  else
11
- raise ReeMapper::TypeError, "should be a time"
11
+ raise ReeMapper::TypeError, "`#{name}` should be a time"
12
12
  end
13
13
  end
14
14
 
15
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Time).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
16
- def cast(value, role: nil)
15
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Time).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
16
+ def cast(value, name:, role: nil)
17
17
  if value.class == Time
18
18
  value
19
19
  elsif value.class == DateTime
@@ -22,20 +22,20 @@ class ReeMapper::Time < ReeMapper::AbstractType
22
22
  begin
23
23
  Time.parse(value)
24
24
  rescue ArgumentError
25
- raise ReeMapper::CoercionError, "is invalid time"
25
+ raise ReeMapper::CoercionError, "`#{name}` is invalid time"
26
26
  end
27
27
  else
28
- raise ReeMapper::TypeError, "should be a time"
28
+ raise ReeMapper::TypeError, "`#{name}` should be a time"
29
29
  end
30
30
  end
31
31
 
32
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Time).throws(ReeMapper::TypeError)
33
- def db_dump(value, role: nil)
34
- serialize(value, role: role)
32
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Time).throws(ReeMapper::TypeError)
33
+ def db_dump(value, name:, role: nil)
34
+ serialize(value, name: name, role: role)
35
35
  end
36
36
 
37
- contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Time).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
38
- def db_load(value, role: nil)
39
- cast(value, role: role)
37
+ contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => Time).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
38
+ def db_load(value, name:, role: nil)
39
+ cast(value, name: name, role: role)
40
40
  end
41
41
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe ReeMapper::Array do
3
+ RSpec.describe 'ReeMapper::Array' do
4
4
  link :build_mapper_factory, from: :ree_mapper
5
5
  link :build_mapper_strategy, from: :ree_mapper
6
6
 
@@ -18,16 +18,25 @@ RSpec.describe ReeMapper::Array do
18
18
  let(:mapper) {
19
19
  mapper_factory.call.use(:cast).use(:serialize).use(:db_dump).use(:db_load) {
20
20
  array :tags, each: integer
21
+ array? :ary_of_ary, each: array(each: integer)
21
22
  }
22
23
  }
23
24
 
24
25
  describe '#serialize' do
25
26
  it {
26
- expect(mapper.serialize({ tags: [1, 2] })).to eq({ tags: [1, 2] })
27
+ expect(mapper.serialize({ tags: [1, 2], ary_of_ary: [[1]] })).to eq({ tags: [1, 2], ary_of_ary: [[1]] })
27
28
  }
28
29
 
29
30
  it {
30
- expect { mapper.serialize({ tags: 1 }) }.to raise_error(ReeMapper::TypeError)
31
+ expect { mapper.serialize({ tags: 1 }) }.to raise_error(ReeMapper::TypeError, "`tags` should be an array")
32
+ }
33
+
34
+ it {
35
+ expect { mapper.serialize({tags: [1], ary_of_ary: ["1"] }) }.to raise_error(ReeMapper::TypeError, "`ary_of_ary[0]` should be an array")
36
+ }
37
+
38
+ it {
39
+ expect { mapper.serialize({tags: [1], ary_of_ary: [[1, "1"]] }) }.to raise_error(ReeMapper::TypeError, "`ary_of_ary[0][1]` should be an integer")
31
40
  }
32
41
  end
33
42
 
@@ -37,7 +46,7 @@ RSpec.describe ReeMapper::Array do
37
46
  }
38
47
 
39
48
  it {
40
- expect { mapper.cast({ 'tags' => 1 }) }.to raise_error(ReeMapper::TypeError)
49
+ expect { mapper.cast({ 'tags' => 1 }) }.to raise_error(ReeMapper::TypeError, "`tags` should be an array")
41
50
  }
42
51
  end
43
52
 
@@ -47,7 +56,7 @@ RSpec.describe ReeMapper::Array do
47
56
  }
48
57
 
49
58
  it {
50
- expect { mapper.db_dump(OpenStruct.new({ tags: 1 })) }.to raise_error(ReeMapper::TypeError)
59
+ expect { mapper.db_dump(OpenStruct.new({ tags: 1 })) }.to raise_error(ReeMapper::TypeError, "`tags` should be an array")
51
60
  }
52
61
  end
53
62
 
@@ -57,7 +66,7 @@ RSpec.describe ReeMapper::Array do
57
66
  }
58
67
 
59
68
  it {
60
- expect { mapper.db_load({ 'tags' => 1 }) }.to raise_error(ReeMapper::TypeError)
69
+ expect { mapper.db_load({ 'tags' => 1 }) }.to raise_error(ReeMapper::TypeError, "`tags` should be an array")
61
70
  }
62
71
  end
63
72
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe ReeMapper::Bool do
3
+ RSpec.describe 'ReeMapper::Bool' do
4
4
  link :build_mapper_factory, from: :ree_mapper
5
5
  link :build_mapper_strategy, from: :ree_mapper
6
6
 
@@ -31,11 +31,11 @@ RSpec.describe ReeMapper::Bool do
31
31
  }
32
32
 
33
33
  it {
34
- expect { mapper.serialize({ bool: 'true' }) }.to raise_error(ReeMapper::TypeError)
34
+ expect { mapper.serialize({ bool: 'true' }) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean")
35
35
  }
36
36
 
37
37
  it {
38
- expect { mapper.serialize({ bool: 1 }) }.to raise_error(ReeMapper::TypeError)
38
+ expect { mapper.serialize({ bool: 1 }) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean")
39
39
  }
40
40
  end
41
41
 
@@ -81,11 +81,11 @@ RSpec.describe ReeMapper::Bool do
81
81
  }
82
82
 
83
83
  it {
84
- expect { mapper.cast({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError)
84
+ expect { mapper.cast({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean")
85
85
  }
86
86
 
87
87
  it {
88
- expect { mapper.cast({ 'bool' => Object.new }) }.to raise_error(ReeMapper::CoercionError)
88
+ expect { mapper.cast({ 'bool' => Object.new }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean")
89
89
  }
90
90
  end
91
91
 
@@ -99,11 +99,11 @@ RSpec.describe ReeMapper::Bool do
99
99
  }
100
100
 
101
101
  it {
102
- expect { mapper.db_dump(OpenStruct.new({ bool: 'true' })) }.to raise_error(ReeMapper::TypeError)
102
+ expect { mapper.db_dump(OpenStruct.new({ bool: 'true' })) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean")
103
103
  }
104
104
 
105
105
  it {
106
- expect { mapper.db_dump(OpenStruct.new({ bool: 1 })) }.to raise_error(ReeMapper::TypeError)
106
+ expect { mapper.db_dump(OpenStruct.new({ bool: 1 })) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean")
107
107
  }
108
108
  end
109
109
 
@@ -149,11 +149,11 @@ RSpec.describe ReeMapper::Bool do
149
149
  }
150
150
 
151
151
  it {
152
- expect { mapper.db_load({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError)
152
+ expect { mapper.db_load({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean")
153
153
  }
154
154
 
155
155
  it {
156
- expect { mapper.db_load({ 'bool' => Object.new }) }.to raise_error(ReeMapper::CoercionError)
156
+ expect { mapper.db_load({ 'bool' => Object.new }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean")
157
157
  }
158
158
  end
159
159
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe ReeMapper::Date do
3
+ RSpec.describe 'ReeMapper::Date' do
4
4
  link :build_mapper_factory, from: :ree_mapper
5
5
  link :build_mapper_strategy, from: :ree_mapper
6
6
 
@@ -27,19 +27,19 @@ RSpec.describe ReeMapper::Date do
27
27
  }
28
28
 
29
29
  it {
30
- expect { mapper.serialize({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError)
30
+ expect { mapper.serialize({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
31
31
  }
32
32
 
33
33
  it {
34
- expect { mapper.serialize({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError)
34
+ expect { mapper.serialize({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
35
35
  }
36
36
 
37
37
  it {
38
- expect { mapper.serialize({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError)
38
+ expect { mapper.serialize({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
39
39
  }
40
40
 
41
41
  it {
42
- expect { mapper.serialize({ date: Object.new }) }.to raise_error(ReeMapper::TypeError)
42
+ expect { mapper.serialize({ date: Object.new }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
43
43
  }
44
44
  end
45
45
 
@@ -61,7 +61,7 @@ RSpec.describe ReeMapper::Date do
61
61
  }
62
62
 
63
63
  it {
64
- expect { mapper.cast({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError)
64
+ expect { mapper.cast({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError, "`date` is invalid date")
65
65
  }
66
66
  end
67
67
 
@@ -83,7 +83,7 @@ RSpec.describe ReeMapper::Date do
83
83
  }
84
84
 
85
85
  it {
86
- expect { mapper.db_load({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError)
86
+ expect { mapper.db_load({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError, "`date` is invalid date")
87
87
  }
88
88
  end
89
89
 
@@ -93,19 +93,19 @@ RSpec.describe ReeMapper::Date do
93
93
  }
94
94
 
95
95
  it {
96
- expect { mapper.db_dump OpenStruct.new({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError)
96
+ expect { mapper.db_dump OpenStruct.new({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
97
97
  }
98
98
 
99
99
  it {
100
- expect { mapper.db_dump OpenStruct.new({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError)
100
+ expect { mapper.db_dump OpenStruct.new({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
101
101
  }
102
102
 
103
103
  it {
104
- expect { mapper.db_dump OpenStruct.new({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError)
104
+ expect { mapper.db_dump OpenStruct.new({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
105
105
  }
106
106
 
107
107
  it {
108
- expect { mapper.db_dump OpenStruct.new({ date: Object.new }) }.to raise_error(ReeMapper::TypeError)
108
+ expect { mapper.db_dump OpenStruct.new({ date: Object.new }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
109
109
  }
110
110
  end
111
111
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe ReeMapper::DateTime do
3
+ RSpec.describe 'ReeMapper::DateTime' do
4
4
  link :build_mapper_factory, from: :ree_mapper
5
5
  link :build_mapper_strategy, from: :ree_mapper
6
6
 
@@ -27,23 +27,23 @@ RSpec.describe ReeMapper::DateTime do
27
27
  }
28
28
 
29
29
  it {
30
- expect { mapper.serialize({ date_time: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError)
30
+ expect { mapper.serialize({ date_time: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
31
31
  }
32
32
 
33
33
  it {
34
- expect { mapper.serialize({ date_time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError)
34
+ expect { mapper.serialize({ date_time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
35
35
  }
36
36
 
37
37
  it {
38
- expect { mapper.serialize({ date_time: DateTime.new(2020).to_s }) }.to raise_error(ReeMapper::TypeError)
38
+ expect { mapper.serialize({ date_time: DateTime.new(2020).to_s }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
39
39
  }
40
40
 
41
41
  it {
42
- expect { mapper.serialize({ date_time: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError)
42
+ expect { mapper.serialize({ date_time: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
43
43
  }
44
44
 
45
45
  it {
46
- expect { mapper.serialize({ date_time: Object.new }) }.to raise_error(ReeMapper::TypeError)
46
+ expect { mapper.serialize({ date_time: Object.new }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
47
47
  }
48
48
  end
49
49
 
@@ -65,15 +65,15 @@ RSpec.describe ReeMapper::DateTime do
65
65
  }
66
66
 
67
67
  it {
68
- expect { mapper.cast({ 'date_time' => Date.new(2020) }) }.to raise_error(ReeMapper::TypeError)
68
+ expect { mapper.cast({ 'date_time' => Date.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
69
69
  }
70
70
 
71
71
  it {
72
- expect { mapper.cast({ 'date_time' => Object.new }) }.to raise_error(ReeMapper::TypeError)
72
+ expect { mapper.cast({ 'date_time' => Object.new }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
73
73
  }
74
74
 
75
75
  it {
76
- expect { mapper.cast({ 'date_time' => 'no date time' }) }.to raise_error(ReeMapper::CoercionError)
76
+ expect { mapper.cast({ 'date_time' => 'no date time' }) }.to raise_error(ReeMapper::CoercionError, "`date_time` is invalid datetime")
77
77
  }
78
78
  end
79
79
 
@@ -83,23 +83,23 @@ RSpec.describe ReeMapper::DateTime do
83
83
  }
84
84
 
85
85
  it {
86
- expect { mapper.db_dump OpenStruct.new({ date_time: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError)
86
+ expect { mapper.db_dump OpenStruct.new({ date_time: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
87
87
  }
88
88
 
89
89
  it {
90
- expect { mapper.db_dump OpenStruct.new({ date_time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError)
90
+ expect { mapper.db_dump OpenStruct.new({ date_time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
91
91
  }
92
92
 
93
93
  it {
94
- expect { mapper.db_dump OpenStruct.new({ date_time: DateTime.new(2020).to_s }) }.to raise_error(ReeMapper::TypeError)
94
+ expect { mapper.db_dump OpenStruct.new({ date_time: DateTime.new(2020).to_s }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
95
95
  }
96
96
 
97
97
  it {
98
- expect { mapper.db_dump OpenStruct.new({ date_time: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError)
98
+ expect { mapper.db_dump OpenStruct.new({ date_time: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
99
99
  }
100
100
 
101
101
  it {
102
- expect { mapper.db_dump OpenStruct.new({ date_time: Object.new }) }.to raise_error(ReeMapper::TypeError)
102
+ expect { mapper.db_dump OpenStruct.new({ date_time: Object.new }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
103
103
  }
104
104
  end
105
105
 
@@ -121,15 +121,15 @@ RSpec.describe ReeMapper::DateTime do
121
121
  }
122
122
 
123
123
  it {
124
- expect { mapper.db_load({ 'date_time' => Date.new(2020) }) }.to raise_error(ReeMapper::TypeError)
124
+ expect { mapper.db_load({ 'date_time' => Date.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
125
125
  }
126
126
 
127
127
  it {
128
- expect { mapper.db_load({ 'date_time' => Object.new }) }.to raise_error(ReeMapper::TypeError)
128
+ expect { mapper.db_load({ 'date_time' => Object.new }) }.to raise_error(ReeMapper::TypeError, "`date_time` should be a datetime")
129
129
  }
130
130
 
131
131
  it {
132
- expect { mapper.db_load({ 'date_time' => 'no date time' }) }.to raise_error(ReeMapper::CoercionError)
132
+ expect { mapper.db_load({ 'date_time' => 'no date time' }) }.to raise_error(ReeMapper::CoercionError, "`date_time` is invalid datetime")
133
133
  }
134
134
  end
135
135
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe ReeMapper::Float do
3
+ RSpec.describe 'ReeMapper::Float' do
4
4
  link :build_mapper_factory, from: :ree_mapper
5
5
  link :build_mapper_strategy, from: :ree_mapper
6
6
 
@@ -31,15 +31,15 @@ RSpec.describe ReeMapper::Float do
31
31
  }
32
32
 
33
33
  it {
34
- expect { mapper.cast({ float: 'a1.1' }) }.to raise_error(ReeMapper::CoercionError)
34
+ expect { mapper.cast({ float: 'a1.1' }) }.to raise_error(ReeMapper::CoercionError, '`float` is invalid float')
35
35
  }
36
36
 
37
37
  it {
38
- expect { mapper.db_load({ float: '1.1a' }) }.to raise_error(ReeMapper::CoercionError)
38
+ expect { mapper.db_load({ float: '1.1a' }) }.to raise_error(ReeMapper::CoercionError, '`float` is invalid float')
39
39
  }
40
40
 
41
41
  it {
42
- expect { mapper.cast({ float: Object.new }) }.to raise_error(ReeMapper::TypeError)
42
+ expect { mapper.cast({ float: Object.new }) }.to raise_error(ReeMapper::TypeError, "`float` should be a float")
43
43
  }
44
44
  end
45
45
 
@@ -49,15 +49,15 @@ RSpec.describe ReeMapper::Float do
49
49
  }
50
50
 
51
51
  it {
52
- expect { mapper.serialize({ float: '1.1' }) }.to raise_error(ReeMapper::TypeError)
52
+ expect { mapper.serialize({ float: '1.1' }) }.to raise_error(ReeMapper::TypeError, "`float` should be a float")
53
53
  }
54
54
 
55
55
  it {
56
- expect { mapper.serialize({ float: nil }) }.to raise_error(ReeMapper::TypeError)
56
+ expect { mapper.serialize({ float: nil }) }.to raise_error(ReeMapper::TypeError, "`float` should be a float")
57
57
  }
58
58
 
59
59
  it {
60
- expect { mapper.serialize({ float: Object.new }) }.to raise_error(ReeMapper::TypeError)
60
+ expect { mapper.serialize({ float: Object.new }) }.to raise_error(ReeMapper::TypeError, "`float` should be a float")
61
61
  }
62
62
  end
63
63
 
@@ -67,15 +67,15 @@ RSpec.describe ReeMapper::Float do
67
67
  }
68
68
 
69
69
  it {
70
- expect { mapper.db_dump({ float: '1.1' }) }.to raise_error(ReeMapper::TypeError)
70
+ expect { mapper.db_dump({ float: '1.1' }) }.to raise_error(ReeMapper::TypeError, "`float` should be a float")
71
71
  }
72
72
 
73
73
  it {
74
- expect { mapper.db_dump({ float: nil }) }.to raise_error(ReeMapper::TypeError)
74
+ expect { mapper.db_dump({ float: nil }) }.to raise_error(ReeMapper::TypeError, "`float` should be a float")
75
75
  }
76
76
 
77
77
  it {
78
- expect { mapper.db_dump({ float: Object.new }) }.to raise_error(ReeMapper::TypeError)
78
+ expect { mapper.db_dump({ float: Object.new }) }.to raise_error(ReeMapper::TypeError, "`float` should be a float")
79
79
  }
80
80
  end
81
81
 
@@ -89,19 +89,19 @@ RSpec.describe ReeMapper::Float do
89
89
  }
90
90
 
91
91
  it {
92
- expect { mapper.db_load({ float: 'a1.1' }) }.to raise_error(ReeMapper::CoercionError)
92
+ expect { mapper.db_load({ float: 'a1.1' }) }.to raise_error(ReeMapper::CoercionError, '`float` is invalid float')
93
93
  }
94
94
 
95
95
  it {
96
- expect { mapper.db_load({ float: '1.1a' }) }.to raise_error(ReeMapper::CoercionError)
96
+ expect { mapper.db_load({ float: '1.1a' }) }.to raise_error(ReeMapper::CoercionError, '`float` is invalid float')
97
97
  }
98
98
 
99
99
  it {
100
- expect { mapper.db_load({ float: nil }) }.to raise_error(ReeMapper::TypeError)
100
+ expect { mapper.db_load({ float: nil }) }.to raise_error(ReeMapper::TypeError, "`float` should be a float")
101
101
  }
102
102
 
103
103
  it {
104
- expect { mapper.db_load({ float: Object.new }) }.to raise_error(ReeMapper::TypeError)
104
+ expect { mapper.db_load({ float: Object.new }) }.to raise_error(ReeMapper::TypeError, "`float` should be a float")
105
105
  }
106
106
  end
107
107
  end
@@ -27,7 +27,11 @@ RSpec.describe 'Mapper Hash' do
27
27
  }
28
28
 
29
29
  it {
30
- expect { mapper.cast({ point: 1 }) }.to raise_error(ReeMapper::TypeError, 'Missing required field `x`')
30
+ expect { mapper.cast({ point: 1 }) }.to raise_error(ReeMapper::TypeError, 'Missing required field `x` for `point`')
31
+ }
32
+
33
+ it {
34
+ expect { mapper.cast({ point: { x: 1, y: 'not integer' } }) }.to raise_error(ReeMapper::CoercionError, '`point[y]` is invalid integer')
31
35
  }
32
36
  end
33
37
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe ReeMapper::Integer do
3
+ RSpec.describe 'ReeMapper::Integer' do
4
4
  link :build_mapper_factory, from: :ree_mapper
5
5
  link :build_mapper_strategy, from: :ree_mapper
6
6
 
@@ -31,15 +31,15 @@ RSpec.describe ReeMapper::Integer do
31
31
  }
32
32
 
33
33
  it {
34
- expect { mapper.cast({ number: 'b1' }) }.to raise_error(ReeMapper::CoercionError)
34
+ expect { mapper.cast({ number: 'b1' }) }.to raise_error(ReeMapper::CoercionError, '`number` is invalid integer')
35
35
  }
36
36
 
37
37
  it {
38
- expect { mapper.cast({ number: '1b' }) }.to raise_error(ReeMapper::CoercionError)
38
+ expect { mapper.cast({ number: '1b' }) }.to raise_error(ReeMapper::CoercionError, '`number` is invalid integer')
39
39
  }
40
40
 
41
41
  it {
42
- expect { mapper.cast({ number: 1.1 }) }.to raise_error(ReeMapper::TypeError)
42
+ expect { mapper.cast({ number: 1.1 }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
43
43
  }
44
44
  end
45
45
 
@@ -49,19 +49,19 @@ RSpec.describe ReeMapper::Integer do
49
49
  }
50
50
 
51
51
  it {
52
- expect { mapper.serialize({ number: '1' }) }.to raise_error(ReeMapper::TypeError)
52
+ expect { mapper.serialize({ number: '1' }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
53
53
  }
54
54
 
55
55
  it {
56
- expect { mapper.serialize({ number: 'b1' }) }.to raise_error(ReeMapper::TypeError)
56
+ expect { mapper.serialize({ number: 'b1' }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
57
57
  }
58
58
 
59
59
  it {
60
- expect { mapper.serialize({ number: '1b' }) }.to raise_error(ReeMapper::TypeError)
60
+ expect { mapper.serialize({ number: '1b' }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
61
61
  }
62
62
 
63
63
  it {
64
- expect { mapper.serialize({ number: 1.1 }) }.to raise_error(ReeMapper::TypeError)
64
+ expect { mapper.serialize({ number: 1.1 }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
65
65
  }
66
66
  end
67
67
 
@@ -71,19 +71,19 @@ RSpec.describe ReeMapper::Integer do
71
71
  }
72
72
 
73
73
  it {
74
- expect { mapper.db_dump({ number: '1' }) }.to raise_error(ReeMapper::TypeError)
74
+ expect { mapper.db_dump({ number: '1' }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
75
75
  }
76
76
 
77
77
  it {
78
- expect { mapper.db_dump({ number: 'b1' }) }.to raise_error(ReeMapper::TypeError)
78
+ expect { mapper.db_dump({ number: 'b1' }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
79
79
  }
80
80
 
81
81
  it {
82
- expect { mapper.db_dump({ number: '1b' }) }.to raise_error(ReeMapper::TypeError)
82
+ expect { mapper.db_dump({ number: '1b' }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
83
83
  }
84
84
 
85
85
  it {
86
- expect { mapper.db_dump({ number: 1.1 }) }.to raise_error(ReeMapper::TypeError)
86
+ expect { mapper.db_dump({ number: 1.1 }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
87
87
  }
88
88
  end
89
89
 
@@ -97,15 +97,15 @@ RSpec.describe ReeMapper::Integer do
97
97
  }
98
98
 
99
99
  it {
100
- expect { mapper.db_load({ number: 'b1' }) }.to raise_error(ReeMapper::CoercionError)
100
+ expect { mapper.db_load({ number: 'b1' }) }.to raise_error(ReeMapper::CoercionError, '`number` is invalid integer')
101
101
  }
102
102
 
103
103
  it {
104
- expect { mapper.db_load({ number: '1b' }) }.to raise_error(ReeMapper::CoercionError)
104
+ expect { mapper.db_load({ number: '1b' }) }.to raise_error(ReeMapper::CoercionError, '`number` is invalid integer')
105
105
  }
106
106
 
107
107
  it {
108
- expect { mapper.db_load({ number: 1.1 }) }.to raise_error(ReeMapper::TypeError)
108
+ expect { mapper.db_load({ number: 1.1 }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
109
109
  }
110
110
  end
111
111
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe ReeMapper::String do
3
+ RSpec.describe 'ReeMapper::String' do
4
4
  link :build_mapper_factory, from: :ree_mapper
5
5
  link :build_mapper_strategy, from: :ree_mapper
6
6
 
@@ -24,40 +24,40 @@ RSpec.describe ReeMapper::String do
24
24
  describe '#serialize' do
25
25
  it { expect(mapper.serialize({ str: 'str' })).to eq({ str: 'str' }) }
26
26
 
27
- it { expect { mapper.serialize({ str: nil }) }.to raise_error(ReeMapper::TypeError) }
27
+ it { expect { mapper.serialize({ str: nil }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
28
28
 
29
- it { expect { mapper.serialize({ str: :sym }) }.to raise_error(ReeMapper::TypeError) }
29
+ it { expect { mapper.serialize({ str: :sym }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
30
30
 
31
- it { expect { mapper.serialize({ str: Object.new }) }.to raise_error(ReeMapper::TypeError) }
31
+ it { expect { mapper.serialize({ str: Object.new }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
32
32
  end
33
33
 
34
34
  describe '#cast' do
35
35
  it { expect(mapper.cast({ str: 'str' })).to eq({ str: 'str' }) }
36
36
 
37
- it { expect { mapper.cast({ str: nil }) }.to raise_error(ReeMapper::TypeError) }
37
+ it { expect { mapper.cast({ str: nil }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
38
38
 
39
- it { expect { mapper.cast({ str: :sym }) }.to raise_error(ReeMapper::TypeError) }
39
+ it { expect { mapper.cast({ str: :sym }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
40
40
 
41
- it { expect { mapper.cast({ str: Object.new }) }.to raise_error(ReeMapper::TypeError) }
41
+ it { expect { mapper.cast({ str: Object.new }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
42
42
  end
43
43
 
44
44
  describe '#db_dump' do
45
45
  it { expect(mapper.db_dump({ str: 'str' })).to eq({ str: 'str' }) }
46
46
 
47
- it { expect { mapper.db_dump({ str: nil }) }.to raise_error(ReeMapper::TypeError) }
47
+ it { expect { mapper.db_dump({ str: nil }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
48
48
 
49
- it { expect { mapper.db_dump({ str: :sym }) }.to raise_error(ReeMapper::TypeError) }
49
+ it { expect { mapper.db_dump({ str: :sym }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
50
50
 
51
- it { expect { mapper.db_dump({ str: Object.new }) }.to raise_error(ReeMapper::TypeError) }
51
+ it { expect { mapper.db_dump({ str: Object.new }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
52
52
  end
53
53
 
54
54
  describe '#db_load' do
55
55
  it { expect(mapper.db_load({ str: 'str' })).to eq({ str: 'str' }) }
56
56
 
57
- it { expect { mapper.db_load({ str: nil }) }.to raise_error(ReeMapper::TypeError) }
57
+ it { expect { mapper.db_load({ str: nil }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
58
58
 
59
- it { expect { mapper.db_load({ str: :sym }) }.to raise_error(ReeMapper::TypeError) }
59
+ it { expect { mapper.db_load({ str: :sym }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
60
60
 
61
- it { expect { mapper.db_load({ str: Object.new }) }.to raise_error(ReeMapper::TypeError) }
61
+ it { expect { mapper.db_load({ str: Object.new }) }.to raise_error(ReeMapper::TypeError, "`str` should be a string") }
62
62
  end
63
63
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe ReeMapper::Time do
3
+ RSpec.describe 'ReeMapper::Time' do
4
4
  link :build_mapper_factory, from: :ree_mapper
5
5
  link :build_mapper_strategy, from: :ree_mapper
6
6
 
@@ -27,23 +27,23 @@ RSpec.describe ReeMapper::Time do
27
27
  }
28
28
 
29
29
  it {
30
- expect { mapper.serialize({ time: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError)
30
+ expect { mapper.serialize({ time: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
31
31
  }
32
32
 
33
33
  it {
34
- expect { mapper.serialize({ time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError)
34
+ expect { mapper.serialize({ time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
35
35
  }
36
36
 
37
37
  it {
38
- expect { mapper.serialize({ time: DateTime.new(2020).to_s }) }.to raise_error(ReeMapper::TypeError)
38
+ expect { mapper.serialize({ time: DateTime.new(2020).to_s }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
39
39
  }
40
40
 
41
41
  it {
42
- expect { mapper.serialize({ time: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError)
42
+ expect { mapper.serialize({ time: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
43
43
  }
44
44
 
45
45
  it {
46
- expect { mapper.serialize({ time: Object.new }) }.to raise_error(ReeMapper::TypeError)
46
+ expect { mapper.serialize({ time: Object.new }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
47
47
  }
48
48
  end
49
49
 
@@ -65,15 +65,15 @@ RSpec.describe ReeMapper::Time do
65
65
  }
66
66
 
67
67
  it {
68
- expect { mapper.cast({ time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError)
68
+ expect { mapper.cast({ time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
69
69
  }
70
70
 
71
71
  it {
72
- expect { mapper.cast({ time: Object.new }) }.to raise_error(ReeMapper::TypeError)
72
+ expect { mapper.cast({ time: Object.new }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
73
73
  }
74
74
 
75
75
  it {
76
- expect { mapper.cast({ time: 'no date time' }) }.to raise_error(ReeMapper::CoercionError)
76
+ expect { mapper.cast({ time: 'no date time' }) }.to raise_error(ReeMapper::CoercionError, "`time` is invalid time")
77
77
  }
78
78
  end
79
79
 
@@ -83,23 +83,23 @@ RSpec.describe ReeMapper::Time do
83
83
  }
84
84
 
85
85
  it {
86
- expect { mapper.serialize({ time: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError)
86
+ expect { mapper.serialize({ time: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
87
87
  }
88
88
 
89
89
  it {
90
- expect { mapper.db_dump({ time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError)
90
+ expect { mapper.db_dump({ time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
91
91
  }
92
92
 
93
93
  it {
94
- expect { mapper.db_dump({ time: Time.new(2020).to_s }) }.to raise_error(ReeMapper::TypeError)
94
+ expect { mapper.db_dump({ time: Time.new(2020).to_s }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
95
95
  }
96
96
 
97
97
  it {
98
- expect { mapper.db_dump({ time: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError)
98
+ expect { mapper.db_dump({ time: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
99
99
  }
100
100
 
101
101
  it {
102
- expect { mapper.db_dump({ time: Object.new }) }.to raise_error(ReeMapper::TypeError)
102
+ expect { mapper.db_dump({ time: Object.new }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
103
103
  }
104
104
  end
105
105
 
@@ -121,15 +121,15 @@ RSpec.describe ReeMapper::Time do
121
121
  }
122
122
 
123
123
  it {
124
- expect { mapper.db_load({ time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError)
124
+ expect { mapper.db_load({ time: Date.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
125
125
  }
126
126
 
127
127
  it {
128
- expect { mapper.db_load({ time: Object.new }) }.to raise_error(ReeMapper::TypeError)
128
+ expect { mapper.db_load({ time: Object.new }) }.to raise_error(ReeMapper::TypeError, "`time` should be a time")
129
129
  }
130
130
 
131
131
  it {
132
- expect { mapper.db_load({ time: 'no date time' }) }.to raise_error(ReeMapper::CoercionError)
132
+ expect { mapper.db_load({ time: 'no date time' }) }.to raise_error(ReeMapper::CoercionError, "`time` is invalid time")
133
133
  }
134
134
  end
135
135
  end
@@ -170,7 +170,7 @@ RSpec.describe 'ReeMapper::MapperFactory type options' do
170
170
  }
171
171
 
172
172
  it {
173
- expect { mapper.cast({ number: nil }) }.to raise_error(ReeMapper::TypeError, 'should be an integer')
173
+ expect { mapper.cast({ number: nil }) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
174
174
  }
175
175
 
176
176
  it {
@@ -183,7 +183,7 @@ RSpec.describe 'ReeMapper::MapperFactory type options' do
183
183
  let(:mapper) { mapper_factory.call.use(:cast) { integer? :number, default: :not_number } }
184
184
 
185
185
  it {
186
- expect { mapper.cast({}) }.to raise_error(ReeMapper::TypeError, 'should be an integer')
186
+ expect { mapper.cast({}) }.to raise_error(ReeMapper::TypeError, '`number` should be an integer')
187
187
  }
188
188
  end
189
189
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.15"
4
+ VERSION = "1.0.17"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-15 00:00:00.000000000 Z
11
+ date: 2022-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree