ree_lib 1.0.93 → 1.0.95
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 +41 -36
- 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_errors/Package.schema.json +10 -7
- data/lib/ree_lib/packages/ree_errors/package/ree_errors/auth_error.rb +8 -8
- data/lib/ree_lib/packages/ree_errors/package/ree_errors/build_error.rb +4 -2
- data/lib/ree_lib/packages/ree_errors/package/ree_errors/conflict_error.rb +8 -8
- data/lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb +89 -6
- data/lib/ree_lib/packages/ree_errors/package/ree_errors/invalid_param_error.rb +9 -9
- data/lib/ree_lib/packages/ree_errors/package/ree_errors/not_found_error.rb +8 -8
- data/lib/ree_lib/packages/ree_errors/package/ree_errors/payment_required_error.rb +8 -8
- data/lib/ree_lib/packages/ree_errors/package/ree_errors/permission_error.rb +8 -8
- data/lib/ree_lib/packages/ree_errors/package/ree_errors/validation_error.rb +8 -8
- data/lib/ree_lib/packages/ree_errors/package/ree_errors.rb +1 -0
- data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/auth_error.schema.json +24 -1
- data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/build_error.schema.json +10 -0
- data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/conflict_error.schema.json +24 -1
- data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/invalid_param_error.schema.json +24 -1
- data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/not_found_error.schema.json +24 -1
- data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/payment_required_error.schema.json +24 -1
- data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/permission_error.schema.json +24 -1
- data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/validation_error.schema.json +24 -1
- data/lib/ree_lib/packages/ree_errors/spec/ree_errors/auth_error_spec.rb +22 -8
- data/lib/ree_lib/packages/ree_errors/spec/ree_errors/invalid_param_error_spec.rb +3 -1
- data/lib/ree_lib/packages/ree_errors/spec/ree_errors/locales/en.yml +6 -1
- data/lib/ree_lib/packages/ree_errors/spec/ree_errors/not_found_error_spec.rb +3 -1
- data/lib/ree_lib/packages/ree_errors/spec/ree_errors/payment_required_error_spec.rb +3 -1
- data/lib/ree_lib/packages/ree_errors/spec/ree_errors/permission_error_spec.rb +3 -1
- data/lib/ree_lib/packages/ree_errors/spec/ree_errors/validation_error_spec.rb +3 -1
- data/lib/ree_lib/packages/ree_i18n/Package.schema.json +7 -0
- data/lib/ree_lib/packages/ree_i18n/package/ree_i18n/functions/check_locale_exists.rb +12 -0
- data/lib/ree_lib/packages/ree_i18n/schemas/ree_i18n/functions/check_locale_exists.schema.json +33 -0
- data/lib/ree_lib/packages/ree_i18n/spec/ree_i18n/functions/check_locale_exists.rb +16 -0
- 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_roda/spec/ree_roda/services/build_swagger_from_routes_spec.rb +7 -4
- data/lib/ree_lib/packages/ree_roda/spec/ree_roda/services/locales/en.yml +3 -1
- data/lib/ree_lib/packages/ree_string/package/ree_string/functions/deconstantize.rb +1 -1
- 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 +5 -3
- data/lib/ree_lib/packages/ree_errors/package/ree_errors/error_factory.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e8b705443daf4776540951e35b4f80fb232b95292bd0c1c589124e24914fb7d
|
4
|
+
data.tar.gz: aefa991e6d624886cca7052a14b8a126222cdf4e29a0438b1b473b6b62020fe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8efb3a06244abe7248da8aefa9438fcab0fad88167ead0017f82ea95aba3b25bf816b093480cb91d87c8948da0af91447c0316d25299e6357e213605f8356fc
|
7
|
+
data.tar.gz: cf257f985bcf7a0b7389567480fa53790d771e56e0c45d915fcec10000f719f9ac0e28bee42468e25f7ce158ac705956509de93d70acf465f2edb83bdef4b050
|
data/Gemfile
CHANGED
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.95)
|
5
5
|
bigdecimal (~> 3.1.6)
|
6
6
|
binding_of_caller (~> 1.0.0)
|
7
7
|
i18n (~> 1.14.1)
|
@@ -15,73 +15,77 @@ PATH
|
|
15
15
|
GEM
|
16
16
|
remote: https://rubygems.org/
|
17
17
|
specs:
|
18
|
-
addressable (2.8.
|
19
|
-
public_suffix (>= 2.0.2, <
|
20
|
-
bigdecimal (3.1.
|
21
|
-
binding_of_caller (1.0.
|
22
|
-
debug_inspector (>=
|
23
|
-
bootsnap (1.
|
18
|
+
addressable (2.8.7)
|
19
|
+
public_suffix (>= 2.0.2, < 7.0)
|
20
|
+
bigdecimal (3.1.8)
|
21
|
+
binding_of_caller (1.0.1)
|
22
|
+
debug_inspector (>= 1.2.0)
|
23
|
+
bootsnap (1.18.3)
|
24
24
|
msgpack (~> 1.2)
|
25
25
|
commander (5.0.0)
|
26
26
|
highline (~> 3.0.0)
|
27
|
-
concurrent-ruby (1.
|
28
|
-
crack (0.
|
27
|
+
concurrent-ruby (1.3.3)
|
28
|
+
crack (1.0.0)
|
29
|
+
bigdecimal
|
29
30
|
rexml
|
30
31
|
crass (1.0.6)
|
31
32
|
debug_inspector (1.2.0)
|
32
|
-
diff-lcs (1.5.
|
33
|
-
faker (3.2
|
33
|
+
diff-lcs (1.5.1)
|
34
|
+
faker (3.4.2)
|
34
35
|
i18n (>= 1.8.11, < 2)
|
35
36
|
hashdiff (1.1.0)
|
36
37
|
highline (3.0.1)
|
37
|
-
i18n (1.14.
|
38
|
+
i18n (1.14.5)
|
38
39
|
concurrent-ruby (~> 1.0)
|
39
40
|
loofah (2.22.0)
|
40
41
|
crass (~> 1.0.2)
|
41
42
|
nokogiri (>= 1.12.0)
|
42
43
|
msgpack (1.7.2)
|
43
|
-
nokogiri (1.16.
|
44
|
+
nokogiri (1.16.7-x86_64-darwin)
|
44
45
|
racc (~> 1.4)
|
45
|
-
nokogiri (1.16.
|
46
|
+
nokogiri (1.16.7-x86_64-linux)
|
46
47
|
racc (~> 1.4)
|
47
|
-
oj (3.16.
|
48
|
+
oj (3.16.4)
|
48
49
|
bigdecimal (>= 3.0)
|
49
|
-
pg (1.5.
|
50
|
-
public_suffix (
|
51
|
-
racc (1.
|
52
|
-
rack (3.
|
50
|
+
pg (1.5.7)
|
51
|
+
public_suffix (6.0.1)
|
52
|
+
racc (1.8.0)
|
53
|
+
rack (3.1.7)
|
53
54
|
rack-test (2.1.0)
|
54
55
|
rack (>= 1.3)
|
55
56
|
rainbow (3.1.1)
|
56
|
-
rake (13.1
|
57
|
-
ree (1.0.
|
57
|
+
rake (13.2.1)
|
58
|
+
ree (1.0.37)
|
58
59
|
commander (~> 5.0.0)
|
59
|
-
rexml (3.2
|
60
|
+
rexml (3.3.2)
|
61
|
+
strscan
|
60
62
|
roda (3.76.0)
|
61
63
|
rack
|
62
|
-
rollbar (3.5.
|
63
|
-
rspec (3.
|
64
|
-
rspec-core (~> 3.
|
65
|
-
rspec-expectations (~> 3.
|
66
|
-
rspec-mocks (~> 3.
|
67
|
-
rspec-core (3.
|
68
|
-
rspec-support (~> 3.
|
69
|
-
rspec-expectations (3.
|
64
|
+
rollbar (3.5.2)
|
65
|
+
rspec (3.13.0)
|
66
|
+
rspec-core (~> 3.13.0)
|
67
|
+
rspec-expectations (~> 3.13.0)
|
68
|
+
rspec-mocks (~> 3.13.0)
|
69
|
+
rspec-core (3.13.0)
|
70
|
+
rspec-support (~> 3.13.0)
|
71
|
+
rspec-expectations (3.13.1)
|
70
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
-
rspec-support (~> 3.
|
72
|
-
rspec-mocks (3.
|
73
|
+
rspec-support (~> 3.13.0)
|
74
|
+
rspec-mocks (3.13.1)
|
73
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
74
|
-
rspec-support (~> 3.
|
75
|
-
rspec-support (3.
|
76
|
+
rspec-support (~> 3.13.0)
|
77
|
+
rspec-support (3.13.1)
|
78
|
+
ruby-prof (1.7.0)
|
76
79
|
sequel (5.76.0)
|
77
80
|
bigdecimal
|
78
81
|
sqlite3 (1.4.4)
|
79
|
-
|
82
|
+
strscan (3.1.0)
|
83
|
+
timecop (0.9.10)
|
80
84
|
tzinfo (2.0.6)
|
81
85
|
concurrent-ruby (~> 1.0)
|
82
86
|
warden (1.2.9)
|
83
87
|
rack (>= 2.0.9)
|
84
|
-
webmock (3.
|
88
|
+
webmock (3.23.1)
|
85
89
|
addressable (>= 2.8.0)
|
86
90
|
crack (>= 0.3.2)
|
87
91
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -102,6 +106,7 @@ DEPENDENCIES
|
|
102
106
|
roda (~> 3.76.0)
|
103
107
|
rollbar (~> 3.5.1)
|
104
108
|
rspec
|
109
|
+
ruby-prof
|
105
110
|
sqlite3 (~> 1.4.4)
|
106
111
|
timecop (~> 0.9.5)
|
107
112
|
warden (~> 1.2.9)
|
@@ -6,25 +6,29 @@ class ReeDao::PgArray < ReeMapper::AbstractWrapper
|
|
6
6
|
contract(
|
7
7
|
Any,
|
8
8
|
Kwargs[
|
9
|
-
name: String,
|
10
9
|
role: Nilor[Symbol, ArrayOf[Symbol]],
|
11
|
-
fields_filters: ArrayOf[ReeMapper::FieldsFilter],
|
12
|
-
location: Nilor[String],
|
10
|
+
fields_filters: Nilor[ArrayOf[ReeMapper::FieldsFilter]],
|
13
11
|
] => Or[Sequel::Postgres::PGArray, String]
|
14
12
|
)
|
15
|
-
def db_dump(value,
|
13
|
+
def db_dump(value, role: nil, fields_filters: nil)
|
16
14
|
if !value.is_a?(Array)
|
17
|
-
raise ReeMapper::TypeError.new("
|
15
|
+
raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
|
18
16
|
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
if subject.fields_filter
|
19
|
+
fields_filters = if fields_filters
|
20
|
+
fields_filters + [subject.fields_filter]
|
21
|
+
else
|
22
|
+
[subject.fields_filter]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
value = value.map.with_index do |item, idx|
|
27
|
+
subject.type.db_dump(item, role:, fields_filters:)
|
28
|
+
rescue ReeMapper::ErrorWithLocation => e
|
29
|
+
e.location ||= subject.location
|
30
|
+
e.prepend_field_name(idx.to_s)
|
31
|
+
raise e
|
28
32
|
end
|
29
33
|
|
30
34
|
if value.empty?
|
@@ -37,25 +41,29 @@ class ReeDao::PgArray < ReeMapper::AbstractWrapper
|
|
37
41
|
contract(
|
38
42
|
Any,
|
39
43
|
Kwargs[
|
40
|
-
name: String,
|
41
44
|
role: Nilor[Symbol, ArrayOf[Symbol]],
|
42
|
-
fields_filters: ArrayOf[ReeMapper::FieldsFilter],
|
43
|
-
location: Nilor[String],
|
45
|
+
fields_filters: Nilor[ArrayOf[ReeMapper::FieldsFilter]],
|
44
46
|
] => Array
|
45
47
|
).throws(ReeMapper::TypeError)
|
46
|
-
def db_load(value,
|
48
|
+
def db_load(value, role: nil, fields_filters: nil)
|
47
49
|
if !value.is_a?(Sequel::Postgres::PGArray)
|
48
|
-
raise ReeMapper::TypeError.new("
|
50
|
+
raise ReeMapper::TypeError.new("should be a Sequel::Postgres::PGArray, got `#{truncate(value.inspect)}`")
|
51
|
+
end
|
52
|
+
|
53
|
+
if subject.fields_filter
|
54
|
+
fields_filters = if fields_filters
|
55
|
+
fields_filters + [subject.fields_filter]
|
56
|
+
else
|
57
|
+
[subject.fields_filter]
|
58
|
+
end
|
49
59
|
end
|
50
60
|
|
51
|
-
value.map.with_index do |
|
52
|
-
subject.type.db_load(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
location: subject.location,
|
58
|
-
)
|
61
|
+
value.map.with_index do |item, idx|
|
62
|
+
subject.type.db_load(item, role:, fields_filters:)
|
63
|
+
rescue ReeMapper::ErrorWithLocation => e
|
64
|
+
e.location ||= subject.location
|
65
|
+
e.prepend_field_name(idx.to_s)
|
66
|
+
raise e
|
59
67
|
end
|
60
68
|
end
|
61
69
|
end
|
@@ -6,10 +6,8 @@ class ReeDao::PgJsonb < ReeMapper::AbstractWrapper
|
|
6
6
|
contract(
|
7
7
|
Any,
|
8
8
|
Kwargs[
|
9
|
-
name: String,
|
10
9
|
role: Nilor[Symbol, ArrayOf[Symbol]],
|
11
|
-
fields_filters: ArrayOf[ReeMapper::FieldsFilter],
|
12
|
-
location: Nilor[String],
|
10
|
+
fields_filters: Nilor[ArrayOf[ReeMapper::FieldsFilter]],
|
13
11
|
] => Or[
|
14
12
|
Sequel::Postgres::JSONBHash,
|
15
13
|
Sequel::Postgres::JSONBArray,
|
@@ -21,29 +19,34 @@ class ReeDao::PgJsonb < ReeMapper::AbstractWrapper
|
|
21
19
|
Sequel::Postgres::JSONBNull
|
22
20
|
]
|
23
21
|
).throws(ReeMapper::TypeError)
|
24
|
-
def db_dump(value,
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
def db_dump(value, role: nil, fields_filters: nil)
|
23
|
+
if subject.fields_filter
|
24
|
+
fields_filters = if fields_filters
|
25
|
+
fields_filters + [subject.fields_filter]
|
26
|
+
else
|
27
|
+
[subject.fields_filter]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
value = begin
|
32
|
+
subject.type.db_dump(value, role:, fields_filters:)
|
33
|
+
rescue ReeMapper::ErrorWithLocation => e
|
34
|
+
e.location ||= subject.location
|
35
|
+
raise e
|
36
|
+
end
|
32
37
|
|
33
38
|
begin
|
34
39
|
Sequel.pg_jsonb_wrap(value)
|
35
40
|
rescue Sequel::Error
|
36
|
-
raise ReeMapper::TypeError.new("
|
41
|
+
raise ReeMapper::TypeError.new("should be an jsonb primitive, got `#{truncate(value.inspect)}`")
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
40
45
|
contract(
|
41
46
|
Any,
|
42
47
|
Kwargs[
|
43
|
-
name: String,
|
44
48
|
role: Nilor[Symbol, ArrayOf[Symbol]],
|
45
|
-
fields_filters: ArrayOf[ReeMapper::FieldsFilter],
|
46
|
-
location: Nilor[String],
|
49
|
+
fields_filters: Nilor[ArrayOf[ReeMapper::FieldsFilter]],
|
47
50
|
] => Or[
|
48
51
|
Hash,
|
49
52
|
Array,
|
@@ -55,7 +58,7 @@ class ReeDao::PgJsonb < ReeMapper::AbstractWrapper
|
|
55
58
|
Rational,
|
56
59
|
]
|
57
60
|
).throws(ReeMapper::TypeError)
|
58
|
-
def db_load(value,
|
61
|
+
def db_load(value, role: nil, fields_filters: nil)
|
59
62
|
value = case value
|
60
63
|
when Sequel::Postgres::JSONBHash
|
61
64
|
ReeObject::ToHash.new.call(value.to_h)
|
@@ -64,15 +67,22 @@ class ReeDao::PgJsonb < ReeMapper::AbstractWrapper
|
|
64
67
|
when Numeric, String, TrueClass, FalseClass, NilClass
|
65
68
|
value
|
66
69
|
else
|
67
|
-
raise ReeMapper::TypeError.new("
|
70
|
+
raise ReeMapper::TypeError.new("should be a Sequel::Postgres::JSONB, got `#{truncate(value.inspect)}`")
|
68
71
|
end
|
69
72
|
|
70
|
-
subject.
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
if subject.fields_filter
|
74
|
+
fields_filters = if fields_filters
|
75
|
+
fields_filters + [subject.fields_filter]
|
76
|
+
else
|
77
|
+
[subject.fields_filter]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
begin
|
82
|
+
subject.type.db_load(value, role:, fields_filters:)
|
83
|
+
rescue ReeMapper::ErrorWithLocation => e
|
84
|
+
e.location ||= subject.location
|
85
|
+
raise e
|
86
|
+
end
|
77
87
|
end
|
78
|
-
end
|
88
|
+
end
|
@@ -8,29 +8,17 @@ class ReeEnum::BaseEnumMapper < ReeMapper::AbstractType
|
|
8
8
|
@enum = enum
|
9
9
|
end
|
10
10
|
|
11
|
-
contract(
|
12
|
-
|
13
|
-
Kwargs[
|
14
|
-
name: String,
|
15
|
-
location: Nilor[String],
|
16
|
-
] => Or[Integer, String]
|
17
|
-
)
|
18
|
-
def db_dump(value, name:, location: nil)
|
11
|
+
contract(ReeEnum::Value => Or[Integer, String])
|
12
|
+
def db_dump(value)
|
19
13
|
value.mapped_value
|
20
14
|
end
|
21
15
|
|
22
|
-
contract(
|
23
|
-
|
24
|
-
Kwargs[
|
25
|
-
name: String,
|
26
|
-
location: Nilor[String],
|
27
|
-
] => ReeEnum::Value
|
28
|
-
).throws(ReeMapper::CoercionError)
|
29
|
-
def db_load(value, name:, location: nil)
|
16
|
+
contract(Or[Integer, String] => ReeEnum::Value).throws(ReeMapper::CoercionError)
|
17
|
+
def db_load(value)
|
30
18
|
enum_val = @enum.get_values.by_mapped_value(value)
|
31
19
|
|
32
20
|
if !enum_val
|
33
|
-
raise ReeMapper::CoercionError.new("
|
21
|
+
raise ReeMapper::CoercionError.new("should be one of #{enum_inspection}, got `#{truncate(value.inspect)}`")
|
34
22
|
end
|
35
23
|
|
36
24
|
enum_val
|
@@ -41,4 +29,4 @@ class ReeEnum::BaseEnumMapper < ReeMapper::AbstractType
|
|
41
29
|
def enum_inspection
|
42
30
|
@enum_inspection ||= truncate(@enum.get_values.each.map(&:to_s).inspect)
|
43
31
|
end
|
44
|
-
end
|
32
|
+
end
|
@@ -2,25 +2,13 @@
|
|
2
2
|
require_relative "base_enum_mapper"
|
3
3
|
|
4
4
|
class ReeEnum::IntegerValueEnumMapper < ReeEnum::BaseEnumMapper
|
5
|
-
contract(
|
6
|
-
|
7
|
-
Kwargs[
|
8
|
-
name: String,
|
9
|
-
location: Nilor[String],
|
10
|
-
] => Integer
|
11
|
-
)
|
12
|
-
def serialize(value, name:, location: nil)
|
5
|
+
contract(ReeEnum::Value => Integer)
|
6
|
+
def serialize(value)
|
13
7
|
value.value
|
14
8
|
end
|
15
9
|
|
16
|
-
contract(
|
17
|
-
|
18
|
-
Kwargs[
|
19
|
-
name: String,
|
20
|
-
location: Nilor[String],
|
21
|
-
] => ReeEnum::Value
|
22
|
-
).throws(ReeMapper::CoercionError)
|
23
|
-
def cast(value, name:, location: nil)
|
10
|
+
contract(Any => ReeEnum::Value).throws(ReeMapper::CoercionError)
|
11
|
+
def cast(value)
|
24
12
|
enum_value = case value
|
25
13
|
when Integer
|
26
14
|
@enum.get_values.by_value(value)
|
@@ -34,9 +22,9 @@ class ReeEnum::IntegerValueEnumMapper < ReeEnum::BaseEnumMapper
|
|
34
22
|
end
|
35
23
|
|
36
24
|
if enum_value.nil?
|
37
|
-
raise ReeMapper::CoercionError.new("
|
25
|
+
raise ReeMapper::CoercionError.new("should be one of #{enum_inspection}, got `#{truncate(value.inspect)}`")
|
38
26
|
end
|
39
27
|
|
40
28
|
enum_value
|
41
29
|
end
|
42
|
-
end
|
30
|
+
end
|
@@ -2,25 +2,13 @@
|
|
2
2
|
require_relative "base_enum_mapper"
|
3
3
|
|
4
4
|
class ReeEnum::StringValueEnumMapper < ReeEnum::BaseEnumMapper
|
5
|
-
contract(
|
6
|
-
|
7
|
-
Kwargs[
|
8
|
-
name: String,
|
9
|
-
location: Nilor[String],
|
10
|
-
] => String
|
11
|
-
)
|
12
|
-
def serialize(value, name:, location: nil)
|
5
|
+
contract(ReeEnum::Value => String)
|
6
|
+
def serialize(value)
|
13
7
|
value.value
|
14
8
|
end
|
15
9
|
|
16
|
-
contract(
|
17
|
-
|
18
|
-
Kwargs[
|
19
|
-
name: String,
|
20
|
-
location: Nilor[String],
|
21
|
-
] => ReeEnum::Value
|
22
|
-
).throws(ReeMapper::CoercionError)
|
23
|
-
def cast(value, name:, location: nil)
|
10
|
+
contract(Any => ReeEnum::Value).throws(ReeMapper::CoercionError)
|
11
|
+
def cast(value)
|
24
12
|
enum_value = case value
|
25
13
|
when String
|
26
14
|
@enum.get_values.by_value(value)
|
@@ -29,9 +17,9 @@ class ReeEnum::StringValueEnumMapper < ReeEnum::BaseEnumMapper
|
|
29
17
|
end
|
30
18
|
|
31
19
|
if enum_value.nil?
|
32
|
-
raise ReeMapper::CoercionError.new("
|
20
|
+
raise ReeMapper::CoercionError.new("should be one of #{enum_inspection}, got `#{truncate(value.inspect)}`")
|
33
21
|
end
|
34
22
|
|
35
23
|
enum_value
|
36
24
|
end
|
37
|
-
end
|
25
|
+
end
|
@@ -9,6 +9,9 @@
|
|
9
9
|
"depends_on": [
|
10
10
|
{
|
11
11
|
"name": "ree_i18n"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"name": "ree_string"
|
12
15
|
}
|
13
16
|
],
|
14
17
|
"env_vars": [
|
@@ -19,7 +22,7 @@
|
|
19
22
|
"name": "auth_error",
|
20
23
|
"schema": "packages/ree_errors/schemas/ree_errors/auth_error.schema.json",
|
21
24
|
"tags": [
|
22
|
-
"
|
25
|
+
"fn"
|
23
26
|
]
|
24
27
|
},
|
25
28
|
{
|
@@ -33,42 +36,42 @@
|
|
33
36
|
"name": "conflict_error",
|
34
37
|
"schema": "packages/ree_errors/schemas/ree_errors/conflict_error.schema.json",
|
35
38
|
"tags": [
|
36
|
-
"
|
39
|
+
"fn"
|
37
40
|
]
|
38
41
|
},
|
39
42
|
{
|
40
43
|
"name": "invalid_param_error",
|
41
44
|
"schema": "packages/ree_errors/schemas/ree_errors/invalid_param_error.schema.json",
|
42
45
|
"tags": [
|
43
|
-
"
|
46
|
+
"fn"
|
44
47
|
]
|
45
48
|
},
|
46
49
|
{
|
47
50
|
"name": "not_found_error",
|
48
51
|
"schema": "packages/ree_errors/schemas/ree_errors/not_found_error.schema.json",
|
49
52
|
"tags": [
|
50
|
-
"
|
53
|
+
"fn"
|
51
54
|
]
|
52
55
|
},
|
53
56
|
{
|
54
57
|
"name": "payment_required_error",
|
55
58
|
"schema": "packages/ree_errors/schemas/ree_errors/payment_required_error.schema.json",
|
56
59
|
"tags": [
|
57
|
-
"
|
60
|
+
"fn"
|
58
61
|
]
|
59
62
|
},
|
60
63
|
{
|
61
64
|
"name": "permission_error",
|
62
65
|
"schema": "packages/ree_errors/schemas/ree_errors/permission_error.schema.json",
|
63
66
|
"tags": [
|
64
|
-
"
|
67
|
+
"fn"
|
65
68
|
]
|
66
69
|
},
|
67
70
|
{
|
68
71
|
"name": "validation_error",
|
69
72
|
"schema": "packages/ree_errors/schemas/ree_errors/validation_error.schema.json",
|
70
73
|
"tags": [
|
71
|
-
"
|
74
|
+
"fn"
|
72
75
|
]
|
73
76
|
}
|
74
77
|
]
|
@@ -1,15 +1,15 @@
|
|
1
|
-
|
1
|
+
class ReeErrors::AuthError
|
2
|
+
include Ree::FnDSL
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
bean :auth_error do
|
4
|
+
fn :auth_error do
|
5
|
+
target :class
|
6
|
+
with_caller
|
7
7
|
link :build_error
|
8
8
|
link 'ree_errors/error', -> { Error }
|
9
9
|
end
|
10
10
|
|
11
|
-
contract Symbol, Nilor[String] => SubclassOf[Error]
|
12
|
-
def
|
13
|
-
build_error(:auth, code,
|
11
|
+
contract Symbol, Nilor[String], Kwargs[msg: Nilor[String]] => SubclassOf[Error]
|
12
|
+
def call(code, locale = nil, msg: nil)
|
13
|
+
build_error(get_caller, :auth, code,locale, msg)
|
14
14
|
end
|
15
15
|
end
|
@@ -5,14 +5,16 @@ class ReeErrors::BuildError
|
|
5
5
|
link 'ree_errors/error', -> { Error }
|
6
6
|
end
|
7
7
|
|
8
|
-
contract Symbol, Symbol, Nilor[String] => SubclassOf[Error]
|
9
|
-
def call(type, code, locale)
|
8
|
+
contract Any, Symbol, Symbol, Nilor[String], Nilor[String] => SubclassOf[Error]
|
9
|
+
def call(caller, type, code, locale, default_msg)
|
10
10
|
klass = Class.new(Error)
|
11
11
|
|
12
12
|
klass.instance_exec do
|
13
|
+
@caller = caller
|
13
14
|
@type = type
|
14
15
|
@code = code
|
15
16
|
@locale = locale
|
17
|
+
@default_msg = default_msg
|
16
18
|
end
|
17
19
|
|
18
20
|
klass
|
@@ -1,15 +1,15 @@
|
|
1
|
-
|
1
|
+
class ReeErrors::ConflictError
|
2
|
+
include Ree::FnDSL
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
bean :conflict_error do
|
4
|
+
fn :conflict_error do
|
5
|
+
target :class
|
6
|
+
with_caller
|
7
7
|
link :build_error
|
8
8
|
link 'ree_errors/error', -> { Error }
|
9
9
|
end
|
10
10
|
|
11
|
-
contract Symbol, Nilor[String] => SubclassOf[Error]
|
12
|
-
def
|
13
|
-
build_error(:conflict, code,
|
11
|
+
contract Symbol, Nilor[String], Kwargs[msg: Nilor[String]] => SubclassOf[Error]
|
12
|
+
def call(code, locale = nil, msg: nil)
|
13
|
+
build_error(get_caller, :conflict, code,locale, msg)
|
14
14
|
end
|
15
15
|
end
|