rest_framework 0.6.2 → 0.6.3
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/VERSION +1 -1
- data/lib/rest_framework/serializers.rb +49 -48
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9310e248327d207a68953d1f629bb9c094c860ee7fe50f1ada4cb87e88e1da43
|
4
|
+
data.tar.gz: c7ffe0f8ef8bf0c0f26b7d918cccbd91c9b1650f144c7ba071d9f9db0c2b4a2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49c1bd1aa35b97b3543ffe3a66b1eb8a19fe339f996483071be1cb6817aa3f8d4848ff90f0b5bd7e20769c9c1c028f605de1e8251cb80bd2fcfb979ec10de2bd
|
7
|
+
data.tar.gz: 1c5e9ef47b970fd883023ac2eb11b3febabfb83d929908de28553b46a668c2136286bef4873f489e5fa263959cbf33a8b8cecef6bce7ace29926983566cad94a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.3
|
@@ -101,53 +101,48 @@ class RESTFramework::NativeSerializer < RESTFramework::BaseSerializer
|
|
101
101
|
return controller_serializer || @controller.class.try(:native_serializer_config)
|
102
102
|
end
|
103
103
|
|
104
|
-
# Helper to filter
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
# Helper to filter a single subconfig for specific keys. By default, keys from `fields` are
|
105
|
+
# removed from the provided `subcfg`. There are two (mutually exclusive) options to adjust the
|
106
|
+
# behavior:
|
107
|
+
#
|
108
|
+
# `add`: Add any `fields` to the `subcfg` which aren't already in the `subcfg`.
|
109
|
+
# `only`: Remove any values found in the `subcfg` not in `fields`.
|
110
|
+
def self.filter_subcfg(subcfg, fields:, add: false, only: false)
|
111
|
+
raise "`add` and `only` conflict with one another" if add && only
|
112
|
+
|
113
|
+
# Don't process nil `subcfg`s.
|
114
|
+
return subcfg unless subcfg
|
109
115
|
|
110
116
|
if subcfg.is_a?(Array)
|
111
|
-
subcfg = subcfg.
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
else
|
117
|
-
subcfg -= except
|
118
|
-
end
|
117
|
+
subcfg = subcfg.transform_values(&:to_sym)
|
118
|
+
|
119
|
+
if add
|
120
|
+
# Only add fields which are not already included.
|
121
|
+
subcfg += fields - subcfg
|
119
122
|
elsif only
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
123
|
+
subcfg.select! { |c| c.in?(fields) }
|
124
|
+
else
|
125
|
+
subcfg -= fields
|
124
126
|
end
|
125
127
|
elsif subcfg.is_a?(Hash)
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
end
|
135
|
-
end
|
136
|
-
elsif !subcfg
|
137
|
-
if additive && except
|
138
|
-
subcfg = except
|
128
|
+
subcfg = subcfg.symbolize_keys
|
129
|
+
|
130
|
+
if add
|
131
|
+
# Add doesn't make sense in a hash context since we wouldn't know the values.
|
132
|
+
elsif only
|
133
|
+
subcfg.select! { |k, _v| k.in?(fields) }
|
134
|
+
else
|
135
|
+
subcfg.reject! { |k, _v| k.in?(fields) }
|
139
136
|
end
|
140
137
|
else # Subcfg is a single element (assume string/symbol).
|
141
138
|
subcfg = subcfg.to_sym
|
142
139
|
|
143
|
-
if
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
elsif only && !additive && !subcfg.in?(only) # Protect only/additive data-leaking.
|
150
|
-
subcfg = []
|
140
|
+
if add
|
141
|
+
subcfg = subcfg.in?(fields) ? fields : [subcfg, *fields]
|
142
|
+
elsif only
|
143
|
+
subcfg = subcfg.in?(fields) ? subcfg : []
|
144
|
+
else
|
145
|
+
subcfg = subcfg.in?(fields) ? [] : subcfg
|
151
146
|
end
|
152
147
|
end
|
153
148
|
|
@@ -166,14 +161,16 @@ class RESTFramework::NativeSerializer < RESTFramework::BaseSerializer
|
|
166
161
|
unless except.empty?
|
167
162
|
# Filter `only`, `except` (additive), `include`, `methods`, and `serializer_methods`.
|
168
163
|
if cfg[:only]
|
169
|
-
cfg[:only] = self.class.filter_subcfg(cfg[:only],
|
164
|
+
cfg[:only] = self.class.filter_subcfg(cfg[:only], fields: except)
|
165
|
+
elsif cfg[:except]
|
166
|
+
cfg[:except] = self.class.filter_subcfg(cfg[:except], fields: except, add: true)
|
170
167
|
else
|
171
|
-
cfg[:except] =
|
168
|
+
cfg[:except] = except
|
172
169
|
end
|
173
|
-
cfg[:include] = self.class.filter_subcfg(cfg[:include],
|
174
|
-
cfg[:methods] = self.class.filter_subcfg(cfg[:methods],
|
170
|
+
cfg[:include] = self.class.filter_subcfg(cfg[:include], fields: except)
|
171
|
+
cfg[:methods] = self.class.filter_subcfg(cfg[:methods], fields: except)
|
175
172
|
cfg[:serializer_methods] = self.class.filter_subcfg(
|
176
|
-
cfg[:serializer_methods],
|
173
|
+
cfg[:serializer_methods], fields: except
|
177
174
|
)
|
178
175
|
end
|
179
176
|
elsif only_param && only = @controller.request.query_parameters[only_param].presence
|
@@ -186,13 +183,17 @@ class RESTFramework::NativeSerializer < RESTFramework::BaseSerializer
|
|
186
183
|
|
187
184
|
# Filter `only`, `except` (additive), `include`, and `methods`.
|
188
185
|
if cfg[:only]
|
189
|
-
cfg[:only] = self.class.filter_subcfg(cfg[:only], only:
|
186
|
+
cfg[:only] = self.class.filter_subcfg(cfg[:only], fields: only, only: true)
|
187
|
+
elsif cfg[:except]
|
188
|
+
cfg[:except] = self.class.filter_subcfg(cfg[:except], fields: except_cols, add: true)
|
190
189
|
else
|
191
|
-
cfg[:
|
190
|
+
cfg[:only] = only
|
192
191
|
end
|
193
|
-
cfg[:include] = self.class.filter_subcfg(cfg[:include], only:
|
194
|
-
cfg[:methods] = self.class.filter_subcfg(cfg[:methods], only:
|
195
|
-
cfg[:serializer_methods] = self.class.filter_subcfg(
|
192
|
+
cfg[:include] = self.class.filter_subcfg(cfg[:include], fields: only, only: true)
|
193
|
+
cfg[:methods] = self.class.filter_subcfg(cfg[:methods], fields: only, only: true)
|
194
|
+
cfg[:serializer_methods] = self.class.filter_subcfg(
|
195
|
+
cfg[:serializer_methods], fields: only, only: true
|
196
|
+
)
|
196
197
|
end
|
197
198
|
end
|
198
199
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory N. Schmit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|