ree_lib 1.0.85 → 1.0.86
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 +5 -5
- data/lib/ree_lib/packages/ree_actions/package/ree_actions/dsl.rb +11 -3
- data/lib/ree_lib/packages/ree_actions/package/ree_actions/errors.rb +3 -0
- data/lib/ree_lib/packages/ree_actions/package/ree_actions.rb +1 -0
- data/lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb +5 -1
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/wrappers/pg_array.rb +2 -2
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/wrappers/pg_jsonb.rb +2 -2
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/wrappers/pg_array_spec.rb +2 -2
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/wrappers/pg_jsonb_spec.rb +8 -6
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/base_enum_mapper.rb +1 -6
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/integer_value_enum_mapper.rb +1 -1
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/string_value_enum_mapper.rb +1 -1
- data/lib/ree_lib/packages/ree_enum/spec/ree_enum/dsl_spec.rb +9 -1
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/abstract_type.rb +6 -0
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/bool.rb +2 -2
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date.rb +3 -3
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date_time.rb +3 -3
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/float.rb +3 -3
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/integer.rb +6 -6
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/rational.rb +3 -3
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/string.rb +1 -1
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/time.rb +3 -3
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/wrappers/abstract_wrapper.rb +7 -0
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/wrappers/array.rb +4 -4
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper.rb +1 -0
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/mapper_factory_spec.rb +2 -2
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/bool_spec.rb +10 -8
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_spec.rb +12 -10
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_time_spec.rb +20 -16
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/float_spec.rb +17 -13
- 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/integer_spec.rb +14 -14
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/rational_spec.rb +16 -12
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/string_spec.rb +24 -12
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/time_spec.rb +20 -16
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/type_options_spec.rb +4 -4
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/wrappers/array_spec.rb +6 -6
- data/lib/ree_lib/packages/ree_roda/package/ree_roda/app.rb +3 -2
- data/lib/ree_lib/packages/ree_roda/spec/ree_roda/app_spec.rb +28 -0
- data/lib/ree_lib/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef4605f8eb48973a2e9ee1c9df9fbef06a4e8be6efe39e2ccd06bc2a945649c3
|
4
|
+
data.tar.gz: 20b1504401c0e996617499d3b9d595bfcfa124036341f0ca81641c7184da5309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6969edfb467a49fa80864d8d27701d2379d846ce2cec01ec80dc0da740978a834597687e2da47ddfb21ec8abbc44a9d7779418e53550fd3bb60237279583cd8
|
7
|
+
data.tar.gz: 463d80dd677fbba864d2c9c9130b88f523e52c0f49c4ee7632ef781ca8c9af5eec19f1230483509bcb981e91b360aa9072918ceaab091ab21bfbb32d207d21e5
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ree_lib (1.0.
|
4
|
+
ree_lib (1.0.86)
|
5
5
|
binding_of_caller (~> 1.0.0)
|
6
6
|
i18n (~> 1.12.0)
|
7
7
|
loofah (~> 2.18.0)
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
crack (0.4.5)
|
27
27
|
rexml
|
28
28
|
crass (1.0.6)
|
29
|
-
debug_inspector (1.
|
29
|
+
debug_inspector (1.2.0)
|
30
30
|
diff-lcs (1.5.0)
|
31
31
|
faker (3.2.0)
|
32
32
|
i18n (>= 1.8.11, < 2)
|
@@ -38,9 +38,9 @@ GEM
|
|
38
38
|
crass (~> 1.0.2)
|
39
39
|
nokogiri (>= 1.5.9)
|
40
40
|
msgpack (1.6.0)
|
41
|
-
nokogiri (1.
|
41
|
+
nokogiri (1.16.0-x86_64-darwin)
|
42
42
|
racc (~> 1.4)
|
43
|
-
nokogiri (1.
|
43
|
+
nokogiri (1.16.0-x86_64-linux)
|
44
44
|
racc (~> 1.4)
|
45
45
|
oj (3.13.23)
|
46
46
|
pg (1.4.6)
|
@@ -51,7 +51,7 @@ GEM
|
|
51
51
|
rack (>= 1.3)
|
52
52
|
rainbow (3.1.1)
|
53
53
|
rake (13.0.6)
|
54
|
-
ree (1.0.
|
54
|
+
ree (1.0.33)
|
55
55
|
commander (~> 4.6.0)
|
56
56
|
rexml (3.2.5)
|
57
57
|
roda (3.58.0)
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
package_require("ree_mapper/errors/type_error")
|
3
|
+
package_require("ree_mapper/errors/coercion_error")
|
4
|
+
|
1
5
|
module ReeActions
|
2
6
|
module DSL
|
3
7
|
def self.included(base)
|
@@ -57,10 +61,14 @@ module ReeActions
|
|
57
61
|
raise ArgumentError.new("ActionCaster does not respond to `cast` method")
|
58
62
|
end
|
59
63
|
|
60
|
-
|
61
|
-
|
62
|
-
|
64
|
+
attrs = begin
|
65
|
+
caster.cast(attrs)
|
66
|
+
rescue ReeMapper::TypeError, ReeMapper::CoercionError => e
|
67
|
+
raise ReeActions::ParamError, e.message
|
68
|
+
end
|
63
69
|
end
|
70
|
+
|
71
|
+
__original_call(user_access, attrs)
|
64
72
|
ensure
|
65
73
|
__ree_dao_drop_cache
|
66
74
|
end
|
@@ -59,6 +59,10 @@ RSpec.describe ReeActions::DSL, type: [:autoclean] do
|
|
59
59
|
|
60
60
|
result = ReeActionsTest::TestAction.new.call('user_access', {user_id: 1})
|
61
61
|
expect(result).to eq(1)
|
62
|
+
|
63
|
+
expect {
|
64
|
+
ReeActionsTest::TestAction.new.call('user_access', {user_id: 'not integer'})
|
65
|
+
}.to raise_error(ReeActions::ParamError)
|
62
66
|
}
|
63
67
|
|
64
68
|
it {
|
@@ -161,7 +165,7 @@ RSpec.describe ReeActions::DSL, type: [:autoclean] do
|
|
161
165
|
users_dao.put(ReeActionsTest::User.new(name: 'Sam', age: 19))
|
162
166
|
end.join
|
163
167
|
end.join
|
164
|
-
|
168
|
+
|
165
169
|
$thread_cache = ReeDao::DaoCache.new.get(:users, $user.id)
|
166
170
|
|
167
171
|
attrs[:user_id]
|
@@ -13,7 +13,7 @@ class ReeDao::PgArray < ReeMapper::AbstractWrapper
|
|
13
13
|
)
|
14
14
|
def db_dump(value, name:, role: nil, fields_filters: [])
|
15
15
|
if !value.is_a?(Array)
|
16
|
-
raise ReeMapper::TypeError, "`#{name}` should be an array"
|
16
|
+
raise ReeMapper::TypeError, "`#{name}` should be an array, got `#{truncate(value.inspect)}`"
|
17
17
|
end
|
18
18
|
|
19
19
|
value = value.map.with_index do |el, index|
|
@@ -42,7 +42,7 @@ class ReeDao::PgArray < ReeMapper::AbstractWrapper
|
|
42
42
|
).throws(ReeMapper::TypeError)
|
43
43
|
def db_load(value, name:, role: nil, fields_filters: [])
|
44
44
|
if !value.is_a?(Sequel::Postgres::PGArray)
|
45
|
-
raise ReeMapper::TypeError, "`#{name}`
|
45
|
+
raise ReeMapper::TypeError, "`#{name}` should be a Sequel::Postgres::PGArray, got `#{truncate(value.inspect)}`"
|
46
46
|
end
|
47
47
|
|
48
48
|
value.map.with_index do |val, index|
|
@@ -31,7 +31,7 @@ class ReeDao::PgJsonb < ReeMapper::AbstractWrapper
|
|
31
31
|
begin
|
32
32
|
Sequel.pg_jsonb_wrap(value)
|
33
33
|
rescue Sequel::Error
|
34
|
-
raise ReeMapper::TypeError, "`#{name}` should be an jsonb primitive"
|
34
|
+
raise ReeMapper::TypeError, "`#{name}` should be an jsonb primitive, got `#{truncate(value.inspect)}`"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -61,7 +61,7 @@ class ReeDao::PgJsonb < ReeMapper::AbstractWrapper
|
|
61
61
|
when Numeric, String, TrueClass, FalseClass, NilClass
|
62
62
|
value
|
63
63
|
else
|
64
|
-
raise ReeMapper::TypeError, "`#{name}`
|
64
|
+
raise ReeMapper::TypeError, "`#{name}` should be a Sequel::Postgres::JSONB, got `#{truncate(value.inspect)}`"
|
65
65
|
end
|
66
66
|
|
67
67
|
subject.type.db_load(
|
@@ -46,7 +46,7 @@ RSpec.describe 'ReeDao::PgArray' do
|
|
46
46
|
it {
|
47
47
|
expect {
|
48
48
|
mapper.db_dump({ tags: 1 })
|
49
|
-
}.to raise_error(ReeMapper::TypeError, "`tags` should be an array")
|
49
|
+
}.to raise_error(ReeMapper::TypeError, "`tags` should be an array, got `1`")
|
50
50
|
}
|
51
51
|
end
|
52
52
|
|
@@ -66,7 +66,7 @@ RSpec.describe 'ReeDao::PgArray' do
|
|
66
66
|
mapper.db_load({
|
67
67
|
tags: 1
|
68
68
|
})
|
69
|
-
}.to raise_error(ReeMapper::TypeError, "`tags`
|
69
|
+
}.to raise_error(ReeMapper::TypeError, "`tags` should be a Sequel::Postgres::PGArray, got `1`")
|
70
70
|
}
|
71
71
|
end
|
72
72
|
end
|
@@ -55,13 +55,14 @@ RSpec.describe 'ReeDao::PgJsonb' do
|
|
55
55
|
it {
|
56
56
|
expect {
|
57
57
|
mapper.db_dump({ numbers: ['1'] })
|
58
|
-
}.to raise_error(ReeMapper::TypeError, "`numbers[0]` should be an integer")
|
58
|
+
}.to raise_error(ReeMapper::TypeError, "`numbers[0]` should be an integer, got `\"1\"`")
|
59
59
|
}
|
60
60
|
|
61
61
|
it {
|
62
|
+
object = Object.new
|
62
63
|
expect {
|
63
|
-
mapper.db_dump({ any:
|
64
|
-
}.to raise_error(ReeMapper::TypeError, "`any` should be an jsonb primitive")
|
64
|
+
mapper.db_dump({ any: object })
|
65
|
+
}.to raise_error(ReeMapper::TypeError, "`any` should be an jsonb primitive, got `#{object.inspect}`")
|
65
66
|
}
|
66
67
|
end
|
67
68
|
|
@@ -87,13 +88,14 @@ RSpec.describe 'ReeDao::PgJsonb' do
|
|
87
88
|
it {
|
88
89
|
expect {
|
89
90
|
mapper.db_load({ numbers: Sequel::Postgres::JSONBArray.new([1.1]) })
|
90
|
-
}.to raise_error(ReeMapper::TypeError, "`numbers[0]` should be an integer")
|
91
|
+
}.to raise_error(ReeMapper::TypeError, "`numbers[0]` should be an integer, got `1.1`")
|
91
92
|
}
|
92
93
|
|
93
94
|
it {
|
95
|
+
object = Object.new
|
94
96
|
expect {
|
95
|
-
mapper.db_load({ numbers:
|
96
|
-
}.to raise_error(ReeMapper::TypeError, "`numbers`
|
97
|
+
mapper.db_load({ numbers: object })
|
98
|
+
}.to raise_error(ReeMapper::TypeError, "`numbers` should be a Sequel::Postgres::JSONB, got `#{object.inspect}`")
|
97
99
|
}
|
98
100
|
end
|
99
101
|
end
|
@@ -30,7 +30,7 @@ class ReeEnum::BaseEnumMapper < ReeMapper::AbstractType
|
|
30
30
|
enum_val = @enum.get_values.by_mapped_value(value)
|
31
31
|
|
32
32
|
if !enum_val
|
33
|
-
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}"
|
33
|
+
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}, got `#{truncate(value.inspect)}`"
|
34
34
|
end
|
35
35
|
|
36
36
|
enum_val
|
@@ -41,9 +41,4 @@ class ReeEnum::BaseEnumMapper < ReeMapper::AbstractType
|
|
41
41
|
def enum_inspection
|
42
42
|
@enum_inspection ||= truncate(@enum.get_values.each.map(&:to_s).inspect)
|
43
43
|
end
|
44
|
-
|
45
|
-
def truncate(str, limit = 180)
|
46
|
-
return str if str.length <= limit
|
47
|
-
"#{str[0..limit]}..."
|
48
|
-
end
|
49
44
|
end
|
@@ -34,7 +34,7 @@ class ReeEnum::IntegerValueEnumMapper < ReeEnum::BaseEnumMapper
|
|
34
34
|
end
|
35
35
|
|
36
36
|
if enum_value.nil?
|
37
|
-
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}"
|
37
|
+
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}, got `#{truncate(value.inspect)}`"
|
38
38
|
end
|
39
39
|
|
40
40
|
enum_value
|
@@ -29,7 +29,7 @@ class ReeEnum::StringValueEnumMapper < ReeEnum::BaseEnumMapper
|
|
29
29
|
end
|
30
30
|
|
31
31
|
if enum_value.nil?
|
32
|
-
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}"
|
32
|
+
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}, got `#{truncate(value.inspect)}`"
|
33
33
|
end
|
34
34
|
|
35
35
|
enum_value
|
@@ -152,7 +152,15 @@ RSpec.describe ReeEnum::DSL do
|
|
152
152
|
type: 'invalid',
|
153
153
|
number: 0,
|
154
154
|
})
|
155
|
-
|
155
|
+
}.to raise_error(ReeMapper::CoercionError, '`type` should be one of ["account"], got `"invalid"`')
|
156
|
+
|
157
|
+
expect {
|
158
|
+
mapper.db_load({
|
159
|
+
state: 'first',
|
160
|
+
type: 'invalid',
|
161
|
+
number: 0,
|
162
|
+
})
|
163
|
+
}.to raise_error(ReeMapper::CoercionError, '`type` should be one of ["account"], got `"invalid"`')
|
156
164
|
|
157
165
|
expect(
|
158
166
|
mapper.cast({
|
@@ -9,7 +9,7 @@ class ReeMapper::Bool < ReeMapper::AbstractType
|
|
9
9
|
if value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
10
10
|
value
|
11
11
|
else
|
12
|
-
raise ReeMapper::TypeError, "`#{name}` should be a boolean"
|
12
|
+
raise ReeMapper::TypeError, "`#{name}` should be a boolean, got `#{truncate(value.inspect)}`"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -20,7 +20,7 @@ class ReeMapper::Bool < ReeMapper::AbstractType
|
|
20
20
|
elsif FALSE_CAST_VALUES.include?(value)
|
21
21
|
false
|
22
22
|
else
|
23
|
-
raise ReeMapper::CoercionError, "`#{name}` is invalid boolean"
|
23
|
+
raise ReeMapper::CoercionError, "`#{name}` is invalid boolean, got `#{truncate(value.inspect)}`"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -8,7 +8,7 @@ class ReeMapper::Date < ReeMapper::AbstractType
|
|
8
8
|
if value.class == Date
|
9
9
|
value
|
10
10
|
else
|
11
|
-
raise ReeMapper::TypeError, "`#{name}` should be a date"
|
11
|
+
raise ReeMapper::TypeError, "`#{name}` should be a date, got `#{truncate(value.inspect)}`"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -22,10 +22,10 @@ class ReeMapper::Date < ReeMapper::AbstractType
|
|
22
22
|
begin
|
23
23
|
Date.parse(value)
|
24
24
|
rescue ArgumentError => e
|
25
|
-
raise ReeMapper::CoercionError, "`#{name}` is invalid date"
|
25
|
+
raise ReeMapper::CoercionError, "`#{name}` is invalid date, got `#{truncate(value.inspect)}`"
|
26
26
|
end
|
27
27
|
else
|
28
|
-
raise ReeMapper::TypeError, "`#{name}` should be a date"
|
28
|
+
raise ReeMapper::TypeError, "`#{name}` should be a date, got `#{truncate(value.inspect)}`"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -8,7 +8,7 @@ class ReeMapper::DateTime < ReeMapper::AbstractType
|
|
8
8
|
if value.class == DateTime
|
9
9
|
value
|
10
10
|
else
|
11
|
-
raise ReeMapper::TypeError, "`#{name}` should be a datetime"
|
11
|
+
raise ReeMapper::TypeError, "`#{name}` should be a datetime, got `#{truncate(value.inspect)}`"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -22,10 +22,10 @@ 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, "`#{name}` is invalid datetime"
|
25
|
+
raise ReeMapper::CoercionError, "`#{name}` is invalid datetime, got `#{truncate(value.inspect)}`"
|
26
26
|
end
|
27
27
|
else
|
28
|
-
raise ReeMapper::TypeError, "`#{name}` should be a datetime"
|
28
|
+
raise ReeMapper::TypeError, "`#{name}` should be a datetime, got `#{truncate(value.inspect)}`"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -6,7 +6,7 @@ class ReeMapper::Float < ReeMapper::AbstractType
|
|
6
6
|
if value.is_a?(Float)
|
7
7
|
value
|
8
8
|
else
|
9
|
-
raise ReeMapper::TypeError, "`#{name}` should be a float"
|
9
|
+
raise ReeMapper::TypeError, "`#{name}` should be a float, got `#{truncate(value.inspect)}`"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -18,12 +18,12 @@ class ReeMapper::Float < ReeMapper::AbstractType
|
|
18
18
|
begin
|
19
19
|
Float(value)
|
20
20
|
rescue ArgumentError => e
|
21
|
-
raise ReeMapper::CoercionError, "`#{name}` is invalid float"
|
21
|
+
raise ReeMapper::CoercionError, "`#{name}` 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, "`#{name}` should be a float"
|
26
|
+
raise ReeMapper::TypeError, "`#{name}` should be a float, got `#{truncate(value.inspect)}`"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -6,7 +6,7 @@ class ReeMapper::Integer < ReeMapper::AbstractType
|
|
6
6
|
if value.is_a? Integer
|
7
7
|
value
|
8
8
|
else
|
9
|
-
raise ReeMapper::TypeError, "`#{name}` should be an integer"
|
9
|
+
raise ReeMapper::TypeError, "`#{name}` should be an integer, got `#{truncate(value.inspect)}`"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -15,13 +15,13 @@ class ReeMapper::Integer < ReeMapper::AbstractType
|
|
15
15
|
if value.is_a?(Integer)
|
16
16
|
value
|
17
17
|
elsif value.is_a?(String)
|
18
|
-
|
19
|
-
if
|
20
|
-
raise ReeMapper::CoercionError, "`#{name}` is invalid integer"
|
18
|
+
coerced_value = Integer(value, exception: false)
|
19
|
+
if coerced_value.nil?
|
20
|
+
raise ReeMapper::CoercionError, "`#{name}` is invalid integer, got `#{truncate(value.inspect)}`"
|
21
21
|
end
|
22
|
-
|
22
|
+
coerced_value
|
23
23
|
else
|
24
|
-
raise ReeMapper::TypeError, "`#{name}` should be an integer"
|
24
|
+
raise ReeMapper::TypeError, "`#{name}` should be an integer, got `#{truncate(value.inspect)}`"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -6,7 +6,7 @@ class ReeMapper::Rational < ReeMapper::AbstractType
|
|
6
6
|
if value.is_a?(Rational)
|
7
7
|
value
|
8
8
|
else
|
9
|
-
raise ReeMapper::TypeError, "`#{name}` should be a rational"
|
9
|
+
raise ReeMapper::TypeError, "`#{name}` should be a rational, got `#{truncate(value.inspect)}`"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -18,12 +18,12 @@ class ReeMapper::Rational < ReeMapper::AbstractType
|
|
18
18
|
begin
|
19
19
|
Rational(value)
|
20
20
|
rescue ArgumentError, ZeroDivisionError => e
|
21
|
-
raise ReeMapper::CoercionError, "`#{name}` is invalid rational"
|
21
|
+
raise ReeMapper::CoercionError, "`#{name}` 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, "`#{name}` should be a rational"
|
26
|
+
raise ReeMapper::TypeError, "`#{name}` should be a rational, got `#{truncate(value.inspect)}`"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -8,7 +8,7 @@ class ReeMapper::Time < ReeMapper::AbstractType
|
|
8
8
|
if value.class == Time
|
9
9
|
value
|
10
10
|
else
|
11
|
-
raise ReeMapper::TypeError, "`#{name}` should be a time"
|
11
|
+
raise ReeMapper::TypeError, "`#{name}` should be a time, got `#{truncate(value.inspect)}`"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -22,10 +22,10 @@ class ReeMapper::Time < ReeMapper::AbstractType
|
|
22
22
|
begin
|
23
23
|
Time.parse(value)
|
24
24
|
rescue ArgumentError
|
25
|
-
raise ReeMapper::CoercionError, "`#{name}` is invalid time"
|
25
|
+
raise ReeMapper::CoercionError, "`#{name}` is invalid time, got `#{truncate(value.inspect)}`"
|
26
26
|
end
|
27
27
|
else
|
28
|
-
raise ReeMapper::TypeError, "`#{name}` should be a time"
|
28
|
+
raise ReeMapper::TypeError, "`#{name}` should be a time, got `#{truncate(value.inspect)}`"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -13,7 +13,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
|
|
13
13
|
end
|
14
14
|
}
|
15
15
|
else
|
16
|
-
raise ReeMapper::TypeError, "`#{name}` should be an array"
|
16
|
+
raise ReeMapper::TypeError, "`#{name}` should be an array, got `#{truncate(value.inspect)}`"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -29,7 +29,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
|
|
29
29
|
end
|
30
30
|
}
|
31
31
|
else
|
32
|
-
raise ReeMapper::TypeError, "`#{name}` should be an array"
|
32
|
+
raise ReeMapper::TypeError, "`#{name}` should be an array, got `#{truncate(value.inspect)}`"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -45,7 +45,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
|
|
45
45
|
end
|
46
46
|
}
|
47
47
|
else
|
48
|
-
raise ReeMapper::TypeError, "`#{name}` should be an array"
|
48
|
+
raise ReeMapper::TypeError, "`#{name}` should be an array, got `#{truncate(value.inspect)}`"
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -61,7 +61,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
|
|
61
61
|
end
|
62
62
|
}
|
63
63
|
else
|
64
|
-
raise ReeMapper::TypeError, "`#{name}` should be an array"
|
64
|
+
raise ReeMapper::TypeError, "`#{name}` should be an array, got `#{truncate(value.inspect)}`"
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -83,7 +83,7 @@ RSpec.describe ReeMapper::MapperFactory do
|
|
83
83
|
let(:round_wrapper) {
|
84
84
|
Class.new(ReeMapper::AbstractWrapper) do
|
85
85
|
def serialize(value, name:, **opts)
|
86
|
-
raise ReeMapper::TypeError, "`#{name}` should be a number" if !value.is_a?(Numeric)
|
86
|
+
raise ReeMapper::TypeError, "`#{name}` should be a number, got `#{truncate(value.inspect)}`" if !value.is_a?(Numeric)
|
87
87
|
|
88
88
|
subject.type.serialize(value.round, name: name, **opts)
|
89
89
|
end
|
@@ -103,7 +103,7 @@ RSpec.describe ReeMapper::MapperFactory do
|
|
103
103
|
def cast(value, name:, **opts)
|
104
104
|
value = subject.type.cast(value, name: name, **opts)
|
105
105
|
|
106
|
-
raise ReeMapper::TypeError, "`#{name}` should be a number" if !value.is_a?(Numeric)
|
106
|
+
raise ReeMapper::TypeError, "`#{name}` should be a number, got `#{truncate(value.inspect)}`" if !value.is_a?(Numeric)
|
107
107
|
value.round
|
108
108
|
end
|
109
109
|
end
|
@@ -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, "`bool` should be a boolean")
|
34
|
+
expect { mapper.serialize({ bool: 'true' }) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean, got `\"true\"`")
|
35
35
|
}
|
36
36
|
|
37
37
|
it {
|
38
|
-
expect { mapper.serialize({ bool: 1 }) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean")
|
38
|
+
expect { mapper.serialize({ bool: 1 }) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean, got `1`")
|
39
39
|
}
|
40
40
|
end
|
41
41
|
|
@@ -81,11 +81,12 @@ RSpec.describe 'ReeMapper::Bool' do
|
|
81
81
|
}
|
82
82
|
|
83
83
|
it {
|
84
|
-
expect { mapper.cast({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean")
|
84
|
+
expect { mapper.cast({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean, got `\"right\"`")
|
85
85
|
}
|
86
86
|
|
87
87
|
it {
|
88
|
-
|
88
|
+
object = Object.new
|
89
|
+
expect { mapper.cast({ 'bool' => object }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean, got `#{object.inspect}`")
|
89
90
|
}
|
90
91
|
end
|
91
92
|
|
@@ -99,11 +100,11 @@ RSpec.describe 'ReeMapper::Bool' do
|
|
99
100
|
}
|
100
101
|
|
101
102
|
it {
|
102
|
-
expect { mapper.db_dump(OpenStruct.new({ bool: 'true' })) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean")
|
103
|
+
expect { mapper.db_dump(OpenStruct.new({ bool: 'true' })) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean, got `\"true\"`")
|
103
104
|
}
|
104
105
|
|
105
106
|
it {
|
106
|
-
expect { mapper.db_dump(OpenStruct.new({ bool: 1 })) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean")
|
107
|
+
expect { mapper.db_dump(OpenStruct.new({ bool: 1 })) }.to raise_error(ReeMapper::TypeError, "`bool` should be a boolean, got `1`")
|
107
108
|
}
|
108
109
|
end
|
109
110
|
|
@@ -149,11 +150,12 @@ RSpec.describe 'ReeMapper::Bool' do
|
|
149
150
|
}
|
150
151
|
|
151
152
|
it {
|
152
|
-
expect { mapper.db_load({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean")
|
153
|
+
expect { mapper.db_load({ 'bool' => 'right' }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean, got `\"right\"`")
|
153
154
|
}
|
154
155
|
|
155
156
|
it {
|
156
|
-
|
157
|
+
object = Object.new
|
158
|
+
expect { mapper.db_load({ 'bool' => object }) }.to raise_error(ReeMapper::CoercionError, "`bool` is invalid boolean, got `#{object.inspect}`")
|
157
159
|
}
|
158
160
|
end
|
159
161
|
end
|
@@ -27,19 +27,20 @@ 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, "`date` should be a date")
|
30
|
+
expect { mapper.serialize({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date, got `#{DateTime.new(2020).inspect}`")
|
31
31
|
}
|
32
32
|
|
33
33
|
it {
|
34
|
-
expect { mapper.serialize({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
|
34
|
+
expect { mapper.serialize({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date, got `#{Time.new(2020).inspect}`")
|
35
35
|
}
|
36
36
|
|
37
37
|
it {
|
38
|
-
expect { mapper.serialize({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
|
38
|
+
expect { mapper.serialize({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date, got `\"2020-01-01\"`")
|
39
39
|
}
|
40
40
|
|
41
41
|
it {
|
42
|
-
|
42
|
+
object = Object.new
|
43
|
+
expect { mapper.serialize({ date: object }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date, got `#{object.inspect}`")
|
43
44
|
}
|
44
45
|
end
|
45
46
|
|
@@ -61,7 +62,7 @@ RSpec.describe 'ReeMapper::Date' do
|
|
61
62
|
}
|
62
63
|
|
63
64
|
it {
|
64
|
-
expect { mapper.cast({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError, "`date` is invalid date")
|
65
|
+
expect { mapper.cast({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError, "`date` is invalid date, got `\"no date\"`")
|
65
66
|
}
|
66
67
|
end
|
67
68
|
|
@@ -83,7 +84,7 @@ RSpec.describe 'ReeMapper::Date' do
|
|
83
84
|
}
|
84
85
|
|
85
86
|
it {
|
86
|
-
expect { mapper.db_load({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError, "`date` is invalid date")
|
87
|
+
expect { mapper.db_load({ 'date' => 'no date' }) }.to raise_error(ReeMapper::CoercionError, "`date` is invalid date, got `\"no date\"`")
|
87
88
|
}
|
88
89
|
end
|
89
90
|
|
@@ -93,19 +94,20 @@ RSpec.describe 'ReeMapper::Date' do
|
|
93
94
|
}
|
94
95
|
|
95
96
|
it {
|
96
|
-
expect { mapper.db_dump OpenStruct.new({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
|
97
|
+
expect { mapper.db_dump OpenStruct.new({ date: DateTime.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date, got `#{DateTime.new(2020).inspect}`")
|
97
98
|
}
|
98
99
|
|
99
100
|
it {
|
100
|
-
expect { mapper.db_dump OpenStruct.new({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
|
101
|
+
expect { mapper.db_dump OpenStruct.new({ date: Time.new(2020) }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date, got `#{Time.new(2020).inspect}`")
|
101
102
|
}
|
102
103
|
|
103
104
|
it {
|
104
|
-
expect { mapper.db_dump OpenStruct.new({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date")
|
105
|
+
expect { mapper.db_dump OpenStruct.new({ date: '2020-01-01' }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date, got `\"2020-01-01\"`")
|
105
106
|
}
|
106
107
|
|
107
108
|
it {
|
108
|
-
|
109
|
+
object = Object.new
|
110
|
+
expect { mapper.db_dump OpenStruct.new({ date: object }) }.to raise_error(ReeMapper::TypeError, "`date` should be a date, got `#{object.inspect}`")
|
109
111
|
}
|
110
112
|
end
|
111
113
|
end
|