ree_lib 1.0.16 → 1.0.18
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/dsl.rb +12 -8
- data/lib/ree_lib/packages/ree_enum/spec/ree_enum/dsl_spec.rb +1 -1
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper.rb +7 -6
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/abstract_type.rb +4 -4
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb +20 -20
- 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 +13 -13
- 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 +13 -13
- 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/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/spec/ree_mapper/types/array_spec.rb +15 -6
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/bool_spec.rb +9 -9
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_spec.rb +11 -11
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_time_spec.rb +17 -17
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/float_spec.rb +14 -14
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/hash_spec.rb +5 -1
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/integer_spec.rb +15 -15
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/string_spec.rb +13 -13
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/time_spec.rb +17 -17
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/type_options_spec.rb +2 -2
- data/lib/ree_lib/version.rb +1 -1
- metadata +2 -4
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/types/pg_array.rb +0 -43
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/types/pg_array_spec.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64fb753de0bc41d6229e85e080565a7eb3cabce192a6cd89a3e07deb0add91f7
|
4
|
+
data.tar.gz: b40c7415b989ea2ce5dd9c46b0a986a4672f8c91764b7ba9dc0604c3ab451e5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f426600c0940004ac34514221aeac311edacd1e40221dcc030990350aa379fc43444a37995d2c1f3933929ecc4d611514e8127a66d6590518cb33f9a6011bc23
|
7
|
+
data.tar.gz: dfc8728bf7b03c7826ba050ca1e992ef700236a79bf34116ccf30e66d2d8850cfb2e81161387aa512b731ba61c7a59bf7857fbce7e913d6e56d365636266fc9a
|
data/Gemfile.lock
CHANGED
@@ -34,25 +34,27 @@ module ReeEnum
|
|
34
34
|
contract(
|
35
35
|
ReeEnum::Value,
|
36
36
|
Kwargs[
|
37
|
+
name: String,
|
37
38
|
role: Nilor[Symbol, ArrayOf[Symbol]]
|
38
39
|
] => String
|
39
40
|
)
|
40
|
-
def serialize(value, role: nil)
|
41
|
+
def serialize(value, name:, role: nil)
|
41
42
|
value.to_s
|
42
43
|
end
|
43
44
|
|
44
45
|
contract(
|
45
46
|
Any,
|
46
47
|
Kwargs[
|
48
|
+
name: String,
|
47
49
|
role: Nilor[Symbol, ArrayOf[Symbol]]
|
48
50
|
] => ReeEnum::Value
|
49
51
|
).throws(ReeMapper::CoercionError)
|
50
|
-
def cast(value, role: nil)
|
52
|
+
def cast(value, name:, role: nil)
|
51
53
|
if value.is_a?(String)
|
52
54
|
enum_val = @enum.values.all.detect { |v| v.to_s == value }
|
53
55
|
|
54
56
|
if !enum_val
|
55
|
-
raise ReeMapper::CoercionError, "should be one of #{@enum.values.all.map(&:to_s).inspect}"
|
57
|
+
raise ReeMapper::CoercionError, "`#{name}` should be one of #{@enum.values.all.map(&:to_s).inspect}"
|
56
58
|
end
|
57
59
|
|
58
60
|
enum_val
|
@@ -60,33 +62,35 @@ module ReeEnum
|
|
60
62
|
enum_val = @enum.values.all.detect { |v| v.to_i == value }
|
61
63
|
|
62
64
|
if !enum_val
|
63
|
-
raise ReeMapper::CoercionError, "should be one of #{@enum.values.all.map(&:to_s).inspect}"
|
65
|
+
raise ReeMapper::CoercionError, "`#{name}` should be one of #{@enum.values.all.map(&:to_s).inspect}"
|
64
66
|
end
|
65
67
|
|
66
68
|
enum_val
|
67
69
|
else
|
68
|
-
raise ReeMapper::CoercionError, "should be one of #{@enum.values.all.map(&:to_s).inspect}"
|
70
|
+
raise ReeMapper::CoercionError, "`#{name}` should be one of #{@enum.values.all.map(&:to_s).inspect}"
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
72
74
|
contract(
|
73
75
|
ReeEnum::Value,
|
74
76
|
Kwargs[
|
77
|
+
name: String,
|
75
78
|
role: Nilor[Symbol, ArrayOf[Symbol]]
|
76
79
|
] => Integer
|
77
80
|
)
|
78
|
-
def db_dump(value, role: nil)
|
81
|
+
def db_dump(value, name:, role: nil)
|
79
82
|
value.to_i
|
80
83
|
end
|
81
84
|
|
82
85
|
contract(
|
83
86
|
Integer,
|
84
87
|
Kwargs[
|
88
|
+
name: String,
|
85
89
|
role: Nilor[Symbol, ArrayOf[Symbol]]
|
86
90
|
] => ReeEnum::Value
|
87
91
|
).throws(ReeMapper::TypeError)
|
88
|
-
def db_load(value, role: nil)
|
89
|
-
cast(value, role: role)
|
92
|
+
def db_load(value, name:, role: nil)
|
93
|
+
cast(value, name: name, role: role)
|
90
94
|
end
|
91
95
|
end
|
92
96
|
|
@@ -112,7 +112,7 @@ RSpec.describe ReeEnum::DSL do
|
|
112
112
|
state: 'first',
|
113
113
|
type: 'invalid',
|
114
114
|
})
|
115
|
-
}.to raise_error(ReeMapper::CoercionError, 'should be one of ["account"]')
|
115
|
+
}.to raise_error(ReeMapper::CoercionError, '`type` should be one of ["account"]')
|
116
116
|
|
117
117
|
expect(
|
118
118
|
mapper.cast({
|
@@ -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
|
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
|
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.
|
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,
|
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,
|
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,
|
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, "
|
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,
|
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,
|
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,
|
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
|