serega 0.18.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +169 -152
- data/VERSION +1 -1
- data/lib/serega/attribute.rb +6 -1
- data/lib/serega/attribute_normalizer.rb +31 -1
- data/lib/serega/config.rb +1 -3
- data/lib/serega/errors.rb +9 -1
- data/lib/serega/object_serializer.rb +12 -7
- data/lib/serega/plan_point.rb +24 -16
- data/lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb +9 -5
- data/lib/serega/plugins/batch/batch.rb +22 -3
- data/lib/serega/plugins/batch/lib/modules/attribute_normalizer.rb +0 -2
- data/lib/serega/plugins/batch/lib/validations/check_opt_batch.rb +1 -1
- data/lib/serega/plugins/camel_case/camel_case.rb +20 -2
- data/lib/serega/plugins/context_metadata/context_metadata.rb +13 -4
- data/lib/serega/plugins/depth_limit/depth_limit.rb +20 -2
- data/lib/serega/plugins/explicit_many_option/explicit_many_option.rb +1 -1
- data/lib/serega/plugins/formatters/formatters.rb +13 -4
- data/lib/serega/plugins/if/if.rb +2 -2
- data/lib/serega/plugins/metadata/meta_attribute.rb +1 -1
- data/lib/serega/plugins/metadata/metadata.rb +4 -4
- data/lib/serega/plugins/preloads/lib/preloads_config.rb +1 -1
- data/lib/serega/plugins/preloads/preloads.rb +22 -2
- data/lib/serega/plugins/presenter/presenter.rb +2 -2
- data/lib/serega/plugins/root/root.rb +25 -5
- data/lib/serega/plugins/string_modifiers/string_modifiers.rb +1 -1
- data/lib/serega/validations/initiate/check_modifiers.rb +12 -5
- metadata +3 -3
@@ -60,11 +60,31 @@ class Serega
|
|
60
60
|
:root
|
61
61
|
end
|
62
62
|
|
63
|
+
# Checks requirements to load plugin
|
64
|
+
#
|
65
|
+
# @param serializer_class [Class<Serega>] Current serializer class
|
66
|
+
# @param opts [Hash] plugin options
|
67
|
+
#
|
68
|
+
# @return [void]
|
69
|
+
#
|
70
|
+
def self.before_load_plugin(serializer_class, **opts)
|
71
|
+
allowed_keys = %i[root root_one root_many]
|
72
|
+
opts.each_key do |key|
|
73
|
+
next if allowed_keys.include?(key)
|
74
|
+
|
75
|
+
raise SeregaError,
|
76
|
+
"Plugin #{plugin_name.inspect} does not accept the #{key.inspect} option. Allowed options:\n" \
|
77
|
+
" - :root [String, Symbol, nil] Specifies common root keyword used when serializing one or multiple objects\n" \
|
78
|
+
" - :root_one [String, Symbol, nil] Specifies root keyword used when serializing one object\n" \
|
79
|
+
" - :root_many [String, Symbol, nil] Specifies root keyword used when serializing multiple objects" \
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
63
83
|
#
|
64
84
|
# Applies plugin code to specific serializer
|
65
85
|
#
|
66
86
|
# @param serializer_class [Class<Serega>] Current serializer class
|
67
|
-
# @param _opts [Hash]
|
87
|
+
# @param _opts [Hash] Plugin options
|
68
88
|
#
|
69
89
|
# @return [void]
|
70
90
|
#
|
@@ -78,7 +98,7 @@ class Serega
|
|
78
98
|
# Adds config options and runs other callbacks after plugin was loaded
|
79
99
|
#
|
80
100
|
# @param serializer_class [Class<Serega>] Current serializer class
|
81
|
-
# @param opts [Hash]
|
101
|
+
# @param opts [Hash] Plugin options
|
82
102
|
#
|
83
103
|
# @return [void]
|
84
104
|
#
|
@@ -102,9 +122,9 @@ class Serega
|
|
102
122
|
#
|
103
123
|
# Configures response root key
|
104
124
|
#
|
105
|
-
# @param root [String, Symbol, nil] Specifies common root when serializing one or multiple objects
|
106
|
-
# @param one [String, Symbol, nil] Specifies root when serializing one object
|
107
|
-
# @param many [String, Symbol, nil] Specifies root when serializing multiple objects
|
125
|
+
# @param root [String, Symbol, nil] Specifies common root keyword used when serializing one or multiple objects
|
126
|
+
# @param one [String, Symbol, nil] Specifies root keyword used when serializing one object
|
127
|
+
# @param many [String, Symbol, nil] Specifies root keyword used when serializing multiple objects
|
108
128
|
#
|
109
129
|
# @return [Hash] Configured root names
|
110
130
|
#
|
@@ -27,7 +27,7 @@ class Serega
|
|
27
27
|
validate(serializer_class, with) if with
|
28
28
|
validate(serializer_class, except) if except
|
29
29
|
|
30
|
-
raise_errors if any_error?
|
30
|
+
raise_errors(serializer_class) if any_error?
|
31
31
|
end
|
32
32
|
|
33
33
|
private
|
@@ -66,12 +66,19 @@ class Serega
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def save_error(name)
|
69
|
-
|
70
|
-
error_attributes << full_attribute_name
|
69
|
+
error_attributes << build_full_attribute_name(*parents_names, name)
|
71
70
|
end
|
72
71
|
|
73
|
-
def
|
74
|
-
|
72
|
+
def build_full_attribute_name(*names)
|
73
|
+
head, *nested = *names
|
74
|
+
result = head.to_s # names are symbols, we need not frozen string
|
75
|
+
nested.each { |nested_name| result << "(" << nested_name.to_s }
|
76
|
+
nested.each { result << ")" }
|
77
|
+
result
|
78
|
+
end
|
79
|
+
|
80
|
+
def raise_errors(serializer_class)
|
81
|
+
raise Serega::AttributeNotExist.new("Not existing attributes: #{error_attributes.join(", ")}", serializer_class, error_attributes)
|
75
82
|
end
|
76
83
|
|
77
84
|
def any_error?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serega
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Glushkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
JSON Serializer
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
143
|
+
rubygems_version: 3.5.3
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: JSON Serializer
|