ree_lib 1.0.92 → 1.0.94

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +3 -1
  4. data/lib/ree_lib/packages/ree_actions/package/ree_actions/dsl.rb +2 -2
  5. data/lib/ree_lib/packages/ree_dao/package/ree_dao/wrappers/pg_array.rb +34 -26
  6. data/lib/ree_lib/packages/ree_dao/package/ree_dao/wrappers/pg_jsonb.rb +35 -25
  7. data/lib/ree_lib/packages/ree_enum/package/ree_enum/base_enum_mapper.rb +6 -18
  8. data/lib/ree_lib/packages/ree_enum/package/ree_enum/integer_value_enum_mapper.rb +6 -18
  9. data/lib/ree_lib/packages/ree_enum/package/ree_enum/string_value_enum_mapper.rb +6 -18
  10. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/errors/error_with_location.rb +47 -14
  11. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb +1 -1
  12. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/fields_filter.rb +11 -20
  13. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper.rb +36 -48
  14. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/abstract_type.rb +2 -2
  15. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/any.rb +8 -8
  16. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/bool.rb +12 -12
  17. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date.rb +14 -14
  18. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date_time.rb +13 -13
  19. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/float.rb +14 -14
  20. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/integer.rb +13 -13
  21. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/rational.rb +14 -14
  22. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/string.rb +12 -12
  23. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/time.rb +13 -13
  24. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/wrappers/array.rb +88 -80
  25. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/benchmarks/mapper_benchmark_spec.rb +41 -1
  26. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/mapper_factory_spec.rb +17 -6
  27. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/hash_spec.rb +1 -1
  28. data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/type_options_spec.rb +7 -26
  29. data/lib/ree_lib/packages/ree_swagger/Package.schema.json +3 -0
  30. data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb +2 -1
  31. data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_request_body_schema.rb +12 -5
  32. data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb +12 -5
  33. data/lib/ree_lib/packages/ree_swagger/package/ree_swagger.rb +1 -0
  34. data/lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/build_parameters.schema.json +8 -0
  35. data/lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/build_request_body_schema.schema.json +1 -1
  36. data/lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/build_serializer_schema.schema.json +1 -1
  37. data/lib/ree_lib/version.rb +1 -1
  38. metadata +2 -2
@@ -1,23 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ReeMapper::Any < ReeMapper::AbstractType
4
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Any)
5
- def serialize(value, name:, location: nil)
4
+ contract(Any => Any)
5
+ def serialize(value)
6
6
  value
7
7
  end
8
8
 
9
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Any)
10
- def cast(value, name:, location: nil)
9
+ contract(Any => Any)
10
+ def cast(value)
11
11
  value
12
12
  end
13
13
 
14
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Any)
15
- def db_dump(value, name:, location: nil)
14
+ contract(Any => Any)
15
+ def db_dump(value)
16
16
  value
17
17
  end
18
18
 
19
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Any)
20
- def db_load(value, name:, location: nil)
19
+ contract(Any => Any)
20
+ def db_load(value)
21
21
  value
22
22
  end
23
23
  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[name: String, location: Nilor[String]] => Bool).throws(ReeMapper::TypeError)
8
- def serialize(value, name:, location: nil)
7
+ contract(Any => Bool).throws(ReeMapper::TypeError)
8
+ def serialize(value)
9
9
  if value.is_a?(TrueClass) || value.is_a?(FalseClass)
10
10
  value
11
11
  else
12
- raise ReeMapper::TypeError.new("`#{name}` should be a boolean, got `#{truncate(value.inspect)}`", location)
12
+ raise ReeMapper::TypeError.new("should be a boolean, got `#{truncate(value.inspect)}`")
13
13
  end
14
14
  end
15
15
 
16
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Bool).throws(ReeMapper::CoercionError)
17
- def cast(value, name:, location: nil)
16
+ contract(Any => Bool).throws(ReeMapper::CoercionError)
17
+ def cast(value)
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.new("`#{name}` is invalid boolean, got `#{truncate(value.inspect)}`", location)
23
+ raise ReeMapper::CoercionError.new("is invalid boolean, got `#{truncate(value.inspect)}`")
24
24
  end
25
25
  end
26
26
 
27
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Bool).throws(ReeMapper::TypeError)
28
- def db_dump(value, name:, location: nil)
29
- serialize(value, name: name, location: location)
27
+ contract(Any => Bool)
28
+ def db_dump(value)
29
+ serialize(value)
30
30
  end
31
31
 
32
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Bool).throws(ReeMapper::CoercionError)
33
- def db_load(value, name:, location: nil)
34
- cast(value, name: name, location: location)
32
+ contract(Any => Bool)
33
+ def db_load(value)
34
+ cast(value)
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[name: String, location: Nilor[String]] => Date).throws(ReeMapper::TypeError)
7
- def serialize(value, name:, location: nil)
6
+ contract(Any => Date).throws(ReeMapper::TypeError)
7
+ def serialize(value)
8
8
  if value.class == Date
9
9
  value
10
10
  else
11
- raise ReeMapper::TypeError.new("`#{name}` should be a date, got `#{truncate(value.inspect)}`", location)
11
+ raise ReeMapper::TypeError.new("should be a date, got `#{truncate(value.inspect)}`")
12
12
  end
13
13
  end
14
14
 
15
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Date).throws(ReeMapper::TypeError, ReeMapper::CoercionError)
16
- def cast(value, name:, location: nil)
15
+ contract(Any => Date).throws(ReeMapper::TypeError, ReeMapper::CoercionError)
16
+ def cast(value)
17
17
  if value.class == Date
18
18
  value
19
19
  elsif value.class == DateTime || value.class == Time
@@ -21,21 +21,21 @@ class ReeMapper::Date < ReeMapper::AbstractType
21
21
  elsif value.is_a?(String)
22
22
  begin
23
23
  Date.parse(value)
24
- rescue ArgumentError => e
25
- raise ReeMapper::CoercionError.new("`#{name}` is invalid date, got `#{truncate(value.inspect)}`", location)
24
+ rescue ArgumentError
25
+ raise ReeMapper::CoercionError.new("is invalid date, got `#{truncate(value.inspect)}`")
26
26
  end
27
27
  else
28
- raise ReeMapper::TypeError.new("`#{name}` should be a date, got `#{truncate(value.inspect)}`", location)
28
+ raise ReeMapper::TypeError.new("should be a date, got `#{truncate(value.inspect)}`")
29
29
  end
30
30
  end
31
31
 
32
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Date).throws(ReeMapper::TypeError)
33
- def db_dump(value, name:, location: nil)
34
- serialize(value, name: name, location: location)
32
+ contract(Any => Date).throws(ReeMapper::TypeError)
33
+ def db_dump(value)
34
+ serialize(value)
35
35
  end
36
36
 
37
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Date).throws(ReeMapper::TypeError, ReeMapper::CoercionError)
38
- def db_load(value, name:, location: nil)
39
- cast(value, name: name, location: location)
37
+ contract(Any => Date).throws(ReeMapper::TypeError, ReeMapper::CoercionError)
38
+ def db_load(value)
39
+ cast(value)
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[name: String, location: Nilor[String]] => DateTime).throws(ReeMapper::TypeError)
7
- def serialize(value, name:, location: nil)
6
+ contract(Any => DateTime).throws(ReeMapper::TypeError)
7
+ def serialize(value)
8
8
  if value.class == DateTime
9
9
  value
10
10
  else
11
- raise ReeMapper::TypeError.new("`#{name}` should be a datetime, got `#{truncate(value.inspect)}`", location)
11
+ raise ReeMapper::TypeError.new("should be a datetime, got `#{truncate(value.inspect)}`")
12
12
  end
13
13
  end
14
14
 
15
- contract(Any, Kwargs[name: String, location: Nilor[String]] => DateTime).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
16
- def cast(value, name:, location: nil)
15
+ contract(Any => DateTime).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
16
+ def cast(value)
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.new("`#{name}` is invalid datetime, got `#{truncate(value.inspect)}`", location)
25
+ raise ReeMapper::CoercionError.new("is invalid datetime, got `#{truncate(value.inspect)}`")
26
26
  end
27
27
  else
28
- raise ReeMapper::TypeError.new("`#{name}` should be a datetime, got `#{truncate(value.inspect)}`", location)
28
+ raise ReeMapper::TypeError.new("should be a datetime, got `#{truncate(value.inspect)}`")
29
29
  end
30
30
  end
31
31
 
32
- contract(Any, Kwargs[name: String, location: Nilor[String]] => DateTime).throws(ReeMapper::TypeError)
33
- def db_dump(value, name:, location: nil)
34
- serialize(value, name: name, location: location)
32
+ contract(Any => DateTime)
33
+ def db_dump(value)
34
+ serialize(value)
35
35
  end
36
36
 
37
- contract(Any, Kwargs[name: String, location: Nilor[String]] => DateTime).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
38
- def db_load(value, name:, location: nil)
39
- cast(value, name: name, location: location)
37
+ contract(Any => DateTime)
38
+ def db_load(value)
39
+ cast(value)
40
40
  end
41
41
  end
@@ -1,39 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ReeMapper::Float < ReeMapper::AbstractType
4
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Float).throws(ReeMapper::TypeError)
5
- def serialize(value, name:, location: nil)
4
+ contract(Any => Float).throws(ReeMapper::TypeError)
5
+ def serialize(value)
6
6
  if value.is_a?(Float)
7
7
  value
8
8
  else
9
- raise ReeMapper::TypeError.new("`#{name}` should be a float, got `#{truncate(value.inspect)}`", location)
9
+ raise ReeMapper::TypeError.new("should be a float, got `#{truncate(value.inspect)}`")
10
10
  end
11
11
  end
12
12
 
13
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Float).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
14
- def cast(value, name:, location: nil)
13
+ contract(Any => Float).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
14
+ def cast(value)
15
15
  if value.is_a?(Numeric)
16
16
  value.to_f
17
17
  elsif value.is_a?(String)
18
18
  begin
19
19
  Float(value)
20
- rescue ArgumentError => e
21
- raise ReeMapper::CoercionError.new("`#{name}` is invalid float, got `#{truncate(value.inspect)}`", location)
20
+ rescue ArgumentError
21
+ raise ReeMapper::CoercionError.new("is invalid float, got `#{truncate(value.inspect)}`")
22
22
  end
23
23
  elsif defined?(BigDecimal) && value.is_a?(BigDecimal)
24
24
  value.to_f
25
25
  else
26
- raise ReeMapper::TypeError.new("`#{name}` should be a float, got `#{truncate(value.inspect)}`", location)
26
+ raise ReeMapper::TypeError.new("should be a float, got `#{truncate(value.inspect)}`")
27
27
  end
28
28
  end
29
29
 
30
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Float).throws(ReeMapper::CoercionError)
31
- def db_dump(value, name:, location: nil)
32
- serialize(value, name: name, location: location)
30
+ contract(Any => Float).throws(ReeMapper::CoercionError)
31
+ def db_dump(value)
32
+ serialize(value)
33
33
  end
34
34
 
35
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Float).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
36
- def db_load(value, name:, location: nil)
37
- cast(value, name: name, location: location)
35
+ contract(Any => Float).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
36
+ def db_load(value)
37
+ cast(value)
38
38
  end
39
39
  end
@@ -1,37 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ReeMapper::Integer < ReeMapper::AbstractType
4
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Integer).throws(ReeMapper::TypeError)
5
- def serialize(value, name:, location: nil)
4
+ contract(Any => Integer).throws(ReeMapper::TypeError)
5
+ def serialize(value)
6
6
  if value.is_a? Integer
7
7
  value
8
8
  else
9
- raise ReeMapper::TypeError.new("`#{name}` should be an integer, got `#{truncate(value.inspect)}`", location)
9
+ raise ReeMapper::TypeError.new("should be an integer, got `#{truncate(value.inspect)}`")
10
10
  end
11
11
  end
12
12
 
13
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Integer).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
14
- def cast(value, name:, location: nil)
13
+ contract(Any => Integer).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
14
+ def cast(value)
15
15
  if value.is_a?(Integer)
16
16
  value
17
17
  elsif value.is_a?(String)
18
18
  coerced_value = Integer(value, exception: false)
19
19
  if coerced_value.nil?
20
- raise ReeMapper::CoercionError.new("`#{name}` is invalid integer, got `#{truncate(value.inspect)}`", location)
20
+ raise ReeMapper::CoercionError.new("is invalid integer, got `#{truncate(value.inspect)}`")
21
21
  end
22
22
  coerced_value
23
23
  else
24
- raise ReeMapper::TypeError.new("`#{name}` should be an integer, got `#{truncate(value.inspect)}`", location)
24
+ raise ReeMapper::TypeError.new("should be an integer, got `#{truncate(value.inspect)}`")
25
25
  end
26
26
  end
27
27
 
28
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Integer).throws(ReeMapper::TypeError)
29
- def db_dump(value, name:, location: nil)
30
- serialize(value, name: name, location: location)
28
+ contract(Any => Integer).throws(ReeMapper::TypeError)
29
+ def db_dump(value)
30
+ serialize(value)
31
31
  end
32
32
 
33
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Integer).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
34
- def db_load(value, name:, location: nil)
35
- cast(value, name: name, location: location)
33
+ contract(Any => Integer).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
34
+ def db_load(value)
35
+ cast(value)
36
36
  end
37
37
  end
@@ -1,39 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ReeMapper::Rational < ReeMapper::AbstractType
4
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Rational).throws(ReeMapper::TypeError)
5
- def serialize(value, name:, location: nil)
4
+ contract(Any => Rational).throws(ReeMapper::TypeError)
5
+ def serialize(value)
6
6
  if value.is_a?(Rational)
7
7
  value
8
8
  else
9
- raise ReeMapper::TypeError.new("`#{name}` should be a rational, got `#{truncate(value.inspect)}`", location)
9
+ raise ReeMapper::TypeError.new("should be a rational, got `#{truncate(value.inspect)}`")
10
10
  end
11
11
  end
12
12
 
13
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Rational).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
14
- def cast(value, name:, location: nil)
13
+ contract(Any => Rational).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
14
+ def cast(value)
15
15
  if value.is_a?(Rational)
16
16
  value
17
17
  elsif value.is_a?(String)
18
18
  begin
19
19
  Rational(value)
20
- rescue ArgumentError, ZeroDivisionError => e
21
- raise ReeMapper::CoercionError.new("`#{name}` is invalid rational, got `#{truncate(value.inspect)}`", location)
20
+ rescue ArgumentError, ZeroDivisionError
21
+ raise ReeMapper::CoercionError.new("is invalid rational, got `#{truncate(value.inspect)}`")
22
22
  end
23
23
  elsif value.is_a?(Numeric)
24
24
  Rational(value)
25
25
  else
26
- raise ReeMapper::TypeError.new("`#{name}` should be a rational, got `#{truncate(value.inspect)}`", location)
26
+ raise ReeMapper::TypeError.new("should be a rational, got `#{truncate(value.inspect)}`")
27
27
  end
28
28
  end
29
29
 
30
- contract(Any, Kwargs[name: String, location: Nilor[String]] => String)
31
- def db_dump(value, name:, location: nil)
32
- serialize(value, name: name, location: location).to_s
30
+ contract(Any => String)
31
+ def db_dump(value)
32
+ serialize(value).to_s
33
33
  end
34
34
 
35
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Rational)
36
- def db_load(value, name:, location: nil)
37
- cast(value, name: name, location: location)
35
+ contract(Any => Rational)
36
+ def db_load(value)
37
+ cast(value)
38
38
  end
39
39
  end
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ReeMapper::String < ReeMapper::AbstractType
4
- contract(Any, Kwargs[name: String, location: Nilor[String]] => String).throws(ReeMapper::TypeError)
5
- def serialize(value, name:, location: nil)
4
+ contract(Any => String).throws(ReeMapper::TypeError)
5
+ def serialize(value)
6
6
  if value.is_a? String
7
7
  value
8
8
  else
9
- raise ReeMapper::TypeError.new("`#{name}` should be a string, got `#{truncate(value.inspect)}`", location)
9
+ raise ReeMapper::TypeError.new("should be a string, got `#{truncate(value.inspect)}`")
10
10
  end
11
11
  end
12
12
 
13
- contract(Any, Kwargs[name: String, location: Nilor[String]] => String).throws(ReeMapper::TypeError)
14
- def cast(value, name:, location: nil)
15
- serialize(value, name: name, location: location)
13
+ contract(Any => String).throws(ReeMapper::TypeError)
14
+ def cast(value)
15
+ serialize(value)
16
16
  end
17
17
 
18
- contract(Any, Kwargs[name: String, location: Nilor[String]] => String).throws(ReeMapper::TypeError)
19
- def db_dump(value, name:, location: nil)
20
- serialize(value, name: name, location: location)
18
+ contract(Any => String).throws(ReeMapper::TypeError)
19
+ def db_dump(value)
20
+ serialize(value)
21
21
  end
22
22
 
23
- contract(Any, Kwargs[name: String, location: Nilor[String]] => String).throws(ReeMapper::TypeError)
24
- def db_load(value, name:, location: nil)
25
- serialize(value, name: name, location: location)
23
+ contract(Any => String).throws(ReeMapper::TypeError)
24
+ def db_load(value)
25
+ serialize(value)
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[name: String, location: Nilor[String]] => Time).throws(ReeMapper::TypeError)
7
- def serialize(value, name:, location: nil)
6
+ contract(Any => Time).throws(ReeMapper::TypeError)
7
+ def serialize(value)
8
8
  if value.class == Time
9
9
  value
10
10
  else
11
- raise ReeMapper::TypeError.new("`#{name}` should be a time, got `#{truncate(value.inspect)}`", location)
11
+ raise ReeMapper::TypeError.new("should be a time, got `#{truncate(value.inspect)}`")
12
12
  end
13
13
  end
14
14
 
15
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Time).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
16
- def cast(value, name:, location: nil)
15
+ contract(Any => Time).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
16
+ def cast(value)
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.new("`#{name}` is invalid time, got `#{truncate(value.inspect)}`", location)
25
+ raise ReeMapper::CoercionError.new("is invalid time, got `#{truncate(value.inspect)}`")
26
26
  end
27
27
  else
28
- raise ReeMapper::TypeError.new("`#{name}` should be a time, got `#{truncate(value.inspect)}`", location)
28
+ raise ReeMapper::TypeError.new("should be a time, got `#{truncate(value.inspect)}`")
29
29
  end
30
30
  end
31
31
 
32
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Time).throws(ReeMapper::TypeError)
33
- def db_dump(value, name:, location: nil)
34
- serialize(value, name: name, location: location)
32
+ contract(Any => Time).throws(ReeMapper::TypeError)
33
+ def db_dump(value)
34
+ serialize(value)
35
35
  end
36
36
 
37
- contract(Any, Kwargs[name: String, location: Nilor[String]] => Time).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
38
- def db_load(value, name:, location: nil)
39
- cast(value, name: name, location: location)
37
+ contract(Any => Time).throws(ReeMapper::CoercionError, ReeMapper::TypeError)
38
+ def db_load(value)
39
+ cast(value)
40
40
  end
41
41
  end
@@ -4,116 +4,124 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
4
4
  contract(
5
5
  Any,
6
6
  Kwargs[
7
- name: String,
8
7
  role: Nilor[Symbol, ArrayOf[Symbol]],
9
- fields_filters: ArrayOf[ReeMapper::FieldsFilter],
10
- location: Nilor[String],
8
+ fields_filters: Nilor[ArrayOf[ReeMapper::FieldsFilter]],
11
9
  ] => Array
12
10
  ).throws(ReeMapper::TypeError)
13
- def serialize(value, name:, role: nil, fields_filters: [], location: nil)
14
- if value.is_a?(Array)
15
- value.map.with_index {
16
- if _1.nil? && subject.null
17
- _1
18
- else
19
- subject.type.serialize(
20
- _1,
21
- name: "#{name}[#{_2}]",
22
- role: role,
23
- fields_filters: fields_filters + [subject.fields_filter],
24
- location: subject.location,
25
- )
26
- end
27
- }
28
- else
29
- raise ReeMapper::TypeError.new("`#{name}` should be an array, got `#{truncate(value.inspect)}`", location)
11
+ def serialize(value, role: nil, fields_filters: nil)
12
+ if !value.is_a?(Array)
13
+ raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
14
+ end
15
+
16
+ if subject.fields_filter
17
+ fields_filters = if fields_filters
18
+ fields_filters + [subject.fields_filter]
19
+ else
20
+ [subject.fields_filter]
21
+ end
22
+ end
23
+
24
+ value.map.with_index do |item, idx|
25
+ next nil if item.nil? && subject.null
26
+
27
+ subject.type.serialize(item, role:, fields_filters:)
28
+ rescue ReeMapper::ErrorWithLocation => e
29
+ e.prepend_field_name(idx.to_s)
30
+ e.location ||= subject.location
31
+ raise e
30
32
  end
31
33
  end
32
34
 
33
35
  contract(
34
36
  Any,
35
37
  Kwargs[
36
- name: String,
37
38
  role: Nilor[Symbol, ArrayOf[Symbol]],
38
- fields_filters: ArrayOf[ReeMapper::FieldsFilter],
39
- location: Nilor[String],
39
+ fields_filters: Nilor[ArrayOf[ReeMapper::FieldsFilter]],
40
40
  ] => Array
41
41
  ).throws(ReeMapper::TypeError)
42
- def cast(value, name:, role: nil, fields_filters: [], location: nil)
43
- if value.is_a?(Array)
44
- value.map.with_index {
45
- if _1.nil? && subject.null
46
- _1
47
- else
48
- subject.type.cast(
49
- _1,
50
- name: "#{name}[#{_2}]",
51
- role: role,
52
- fields_filters: fields_filters + [subject.fields_filter],
53
- location: subject.location,
54
- )
55
- end
56
- }
57
- else
58
- raise ReeMapper::TypeError.new("`#{name}` should be an array, got `#{truncate(value.inspect)}`", location)
42
+ def cast(value, role: nil, fields_filters: nil)
43
+ if !value.is_a?(Array)
44
+ raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
45
+ end
46
+
47
+ if subject.fields_filter
48
+ fields_filters = if fields_filters
49
+ fields_filters + [subject.fields_filter]
50
+ else
51
+ [subject.fields_filter]
52
+ end
53
+ end
54
+
55
+ value.map.with_index do |item, idx|
56
+ next nil if item.nil? && subject.null
57
+
58
+ subject.type.cast(item, role:, fields_filters:)
59
+ rescue ReeMapper::ErrorWithLocation => e
60
+ e.prepend_field_name(idx.to_s)
61
+ e.location ||= subject.location
62
+ raise e
59
63
  end
60
64
  end
61
65
 
62
66
  contract(
63
67
  Any,
64
68
  Kwargs[
65
- name: String,
66
69
  role: Nilor[Symbol, ArrayOf[Symbol]],
67
- fields_filters: ArrayOf[ReeMapper::FieldsFilter],
68
- location: Nilor[String],
70
+ fields_filters: Nilor[ArrayOf[ReeMapper::FieldsFilter]],
69
71
  ] => Array
70
72
  ).throws(ReeMapper::TypeError)
71
- def db_dump(value, name:, role: nil, fields_filters: [], location: nil)
72
- if value.is_a?(Array)
73
- value.map.with_index {
74
- if _1.nil? && subject.null
75
- _1
76
- else
77
- subject.type.db_dump(
78
- _1,
79
- name: "#{name}[#{_2}]",
80
- role: role,
81
- fields_filters: fields_filters + [subject.fields_filter],
82
- location: subject.location,
83
- )
84
- end
85
- }
86
- else
87
- raise ReeMapper::TypeError.new("`#{name}` should be an array, got `#{truncate(value.inspect)}`", location)
73
+ def db_dump(value, role: nil, fields_filters: nil)
74
+ if !value.is_a?(Array)
75
+ raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
76
+ end
77
+
78
+ if subject.fields_filter
79
+ fields_filters = if fields_filters
80
+ fields_filters + [subject.fields_filter]
81
+ else
82
+ [subject.fields_filter]
83
+ end
84
+ end
85
+
86
+ value.map.with_index do |item, idx|
87
+ next nil if item.nil? && subject.null
88
+
89
+ subject.type.db_dump(item, role:, fields_filters:)
90
+ rescue ReeMapper::ErrorWithLocation => e
91
+ e.prepend_field_name(idx.to_s)
92
+ e.location ||= subject.location
93
+ raise e
88
94
  end
89
95
  end
90
96
 
91
97
  contract(
92
98
  Any,
93
99
  Kwargs[
94
- name: String,
95
100
  role: Nilor[Symbol, ArrayOf[Symbol]],
96
- fields_filters: ArrayOf[ReeMapper::FieldsFilter],
97
- location: Nilor[String],
101
+ fields_filters: Nilor[ArrayOf[ReeMapper::FieldsFilter]],
98
102
  ] => Array
99
103
  ).throws(ReeMapper::TypeError)
100
- def db_load(value, name:, role: nil, fields_filters: [], location: nil)
101
- if value.is_a?(Array)
102
- value.map.with_index {
103
- if _1.nil? && subject.null
104
- _1
105
- else
106
- subject.type.db_load(
107
- _1,
108
- name: "#{name}[#{_2}]",
109
- role: role,
110
- fields_filters: fields_filters + [subject.fields_filter],
111
- location: subject.location,
112
- )
113
- end
114
- }
115
- else
116
- raise ReeMapper::TypeError.new("`#{name}` should be an array, got `#{truncate(value.inspect)}`", location)
104
+ def db_load(value, role: nil, fields_filters: nil)
105
+ if !value.is_a?(Array)
106
+ raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
107
+ end
108
+
109
+ if subject.fields_filter
110
+ fields_filters = if fields_filters
111
+ fields_filters + [subject.fields_filter]
112
+ else
113
+ [subject.fields_filter]
114
+ end
115
+ end
116
+
117
+ value.map.with_index do |item, idx|
118
+ next nil if item.nil? && subject.null
119
+
120
+ subject.type.db_load(item, role:, fields_filters:)
121
+ rescue ReeMapper::ErrorWithLocation => e
122
+ e.prepend_field_name(idx.to_s)
123
+ e.location ||= subject.location
124
+ raise e
117
125
  end
118
126
  end
119
127
  end