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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -1
- data/lib/ree_lib/packages/ree_actions/package/ree_actions/dsl.rb +2 -2
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/wrappers/pg_array.rb +34 -26
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/wrappers/pg_jsonb.rb +35 -25
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/base_enum_mapper.rb +6 -18
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/integer_value_enum_mapper.rb +6 -18
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/string_value_enum_mapper.rb +6 -18
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/errors/error_with_location.rb +47 -14
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb +1 -1
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/fields_filter.rb +11 -20
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper.rb +36 -48
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/abstract_type.rb +2 -2
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/any.rb +8 -8
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/bool.rb +12 -12
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date.rb +14 -14
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date_time.rb +13 -13
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/float.rb +14 -14
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/integer.rb +13 -13
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/rational.rb +14 -14
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/string.rb +12 -12
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/time.rb +13 -13
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/wrappers/array.rb +88 -80
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/benchmarks/mapper_benchmark_spec.rb +41 -1
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/mapper_factory_spec.rb +17 -6
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/hash_spec.rb +1 -1
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/type_options_spec.rb +7 -26
- data/lib/ree_lib/packages/ree_swagger/Package.schema.json +3 -0
- data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb +2 -1
- data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_request_body_schema.rb +12 -5
- data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb +12 -5
- data/lib/ree_lib/packages/ree_swagger/package/ree_swagger.rb +1 -0
- data/lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/build_parameters.schema.json +8 -0
- data/lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/build_request_body_schema.schema.json +1 -1
- data/lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/build_serializer_schema.schema.json +1 -1
- data/lib/ree_lib/version.rb +1 -1
- 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
|
5
|
-
def serialize(value
|
4
|
+
contract(Any => Any)
|
5
|
+
def serialize(value)
|
6
6
|
value
|
7
7
|
end
|
8
8
|
|
9
|
-
contract(Any
|
10
|
-
def cast(value
|
9
|
+
contract(Any => Any)
|
10
|
+
def cast(value)
|
11
11
|
value
|
12
12
|
end
|
13
13
|
|
14
|
-
contract(Any
|
15
|
-
def db_dump(value
|
14
|
+
contract(Any => Any)
|
15
|
+
def db_dump(value)
|
16
16
|
value
|
17
17
|
end
|
18
18
|
|
19
|
-
contract(Any
|
20
|
-
def db_load(value
|
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
|
8
|
-
def serialize(value
|
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("
|
12
|
+
raise ReeMapper::TypeError.new("should be a boolean, got `#{truncate(value.inspect)}`")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
contract(Any
|
17
|
-
def cast(value
|
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("
|
23
|
+
raise ReeMapper::CoercionError.new("is invalid boolean, got `#{truncate(value.inspect)}`")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
contract(Any
|
28
|
-
def db_dump(value
|
29
|
-
serialize(value
|
27
|
+
contract(Any => Bool)
|
28
|
+
def db_dump(value)
|
29
|
+
serialize(value)
|
30
30
|
end
|
31
31
|
|
32
|
-
contract(Any
|
33
|
-
def db_load(value
|
34
|
-
cast(value
|
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
|
7
|
-
def serialize(value
|
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("
|
11
|
+
raise ReeMapper::TypeError.new("should be a date, got `#{truncate(value.inspect)}`")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
contract(Any
|
16
|
-
def cast(value
|
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
|
25
|
-
raise ReeMapper::CoercionError.new("
|
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("
|
28
|
+
raise ReeMapper::TypeError.new("should be a date, got `#{truncate(value.inspect)}`")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
contract(Any
|
33
|
-
def db_dump(value
|
34
|
-
serialize(value
|
32
|
+
contract(Any => Date).throws(ReeMapper::TypeError)
|
33
|
+
def db_dump(value)
|
34
|
+
serialize(value)
|
35
35
|
end
|
36
36
|
|
37
|
-
contract(Any
|
38
|
-
def db_load(value
|
39
|
-
cast(value
|
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
|
7
|
-
def serialize(value
|
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("
|
11
|
+
raise ReeMapper::TypeError.new("should be a datetime, got `#{truncate(value.inspect)}`")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
contract(Any
|
16
|
-
def cast(value
|
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("
|
25
|
+
raise ReeMapper::CoercionError.new("is invalid datetime, got `#{truncate(value.inspect)}`")
|
26
26
|
end
|
27
27
|
else
|
28
|
-
raise ReeMapper::TypeError.new("
|
28
|
+
raise ReeMapper::TypeError.new("should be a datetime, got `#{truncate(value.inspect)}`")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
contract(Any
|
33
|
-
def db_dump(value
|
34
|
-
serialize(value
|
32
|
+
contract(Any => DateTime)
|
33
|
+
def db_dump(value)
|
34
|
+
serialize(value)
|
35
35
|
end
|
36
36
|
|
37
|
-
contract(Any
|
38
|
-
def db_load(value
|
39
|
-
cast(value
|
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
|
5
|
-
def serialize(value
|
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("
|
9
|
+
raise ReeMapper::TypeError.new("should be a float, got `#{truncate(value.inspect)}`")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
contract(Any
|
14
|
-
def cast(value
|
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
|
21
|
-
raise ReeMapper::CoercionError.new("
|
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("
|
26
|
+
raise ReeMapper::TypeError.new("should be a float, got `#{truncate(value.inspect)}`")
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
contract(Any
|
31
|
-
def db_dump(value
|
32
|
-
serialize(value
|
30
|
+
contract(Any => Float).throws(ReeMapper::CoercionError)
|
31
|
+
def db_dump(value)
|
32
|
+
serialize(value)
|
33
33
|
end
|
34
34
|
|
35
|
-
contract(Any
|
36
|
-
def db_load(value
|
37
|
-
cast(value
|
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
|
5
|
-
def serialize(value
|
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("
|
9
|
+
raise ReeMapper::TypeError.new("should be an integer, got `#{truncate(value.inspect)}`")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
contract(Any
|
14
|
-
def cast(value
|
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("
|
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("
|
24
|
+
raise ReeMapper::TypeError.new("should be an integer, got `#{truncate(value.inspect)}`")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
contract(Any
|
29
|
-
def db_dump(value
|
30
|
-
serialize(value
|
28
|
+
contract(Any => Integer).throws(ReeMapper::TypeError)
|
29
|
+
def db_dump(value)
|
30
|
+
serialize(value)
|
31
31
|
end
|
32
32
|
|
33
|
-
contract(Any
|
34
|
-
def db_load(value
|
35
|
-
cast(value
|
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
|
5
|
-
def serialize(value
|
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("
|
9
|
+
raise ReeMapper::TypeError.new("should be a rational, got `#{truncate(value.inspect)}`")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
contract(Any
|
14
|
-
def cast(value
|
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
|
21
|
-
raise ReeMapper::CoercionError.new("
|
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("
|
26
|
+
raise ReeMapper::TypeError.new("should be a rational, got `#{truncate(value.inspect)}`")
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
contract(Any
|
31
|
-
def db_dump(value
|
32
|
-
serialize(value
|
30
|
+
contract(Any => String)
|
31
|
+
def db_dump(value)
|
32
|
+
serialize(value).to_s
|
33
33
|
end
|
34
34
|
|
35
|
-
contract(Any
|
36
|
-
def db_load(value
|
37
|
-
cast(value
|
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
|
5
|
-
def serialize(value
|
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("
|
9
|
+
raise ReeMapper::TypeError.new("should be a string, got `#{truncate(value.inspect)}`")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
contract(Any
|
14
|
-
def cast(value
|
15
|
-
serialize(value
|
13
|
+
contract(Any => String).throws(ReeMapper::TypeError)
|
14
|
+
def cast(value)
|
15
|
+
serialize(value)
|
16
16
|
end
|
17
17
|
|
18
|
-
contract(Any
|
19
|
-
def db_dump(value
|
20
|
-
serialize(value
|
18
|
+
contract(Any => String).throws(ReeMapper::TypeError)
|
19
|
+
def db_dump(value)
|
20
|
+
serialize(value)
|
21
21
|
end
|
22
22
|
|
23
|
-
contract(Any
|
24
|
-
def db_load(value
|
25
|
-
serialize(value
|
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
|
7
|
-
def serialize(value
|
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("
|
11
|
+
raise ReeMapper::TypeError.new("should be a time, got `#{truncate(value.inspect)}`")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
contract(Any
|
16
|
-
def cast(value
|
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("
|
25
|
+
raise ReeMapper::CoercionError.new("is invalid time, got `#{truncate(value.inspect)}`")
|
26
26
|
end
|
27
27
|
else
|
28
|
-
raise ReeMapper::TypeError.new("
|
28
|
+
raise ReeMapper::TypeError.new("should be a time, got `#{truncate(value.inspect)}`")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
contract(Any
|
33
|
-
def db_dump(value
|
34
|
-
serialize(value
|
32
|
+
contract(Any => Time).throws(ReeMapper::TypeError)
|
33
|
+
def db_dump(value)
|
34
|
+
serialize(value)
|
35
35
|
end
|
36
36
|
|
37
|
-
contract(Any
|
38
|
-
def db_load(value
|
39
|
-
cast(value
|
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,
|
14
|
-
if value.is_a?(Array)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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,
|
43
|
-
if value.is_a?(Array)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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,
|
72
|
-
if value.is_a?(Array)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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,
|
101
|
-
if value.is_a?(Array)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|