rest_framework 2.0.0.beta2 → 2.0.0.beta3
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/native_serializer.rb +39 -9
- 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: 7cedfa02dac90388b712f4e15e29d07a40e45df23847bebf5da02eea03862e75
|
|
4
|
+
data.tar.gz: 2de9c962810e9473dd5eb68c2ee42da764ed793e341049a49d9f4ca8d34fa48e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f52b1b1075fef181d9e771df56f1c088c73601d600606411974febb1bb544facacc7d16d83c2b34929acc0d0f44a0e518098a3a121fcdf27f7e5f12be3a5d8ca
|
|
7
|
+
data.tar.gz: c08ffc3af87bb7d7337dd1a908c7c6199fa3e70328b06dbebd1a691a0c3f235224b0119026eda4274f555385254383d2a7a29719b339f5c487f0ee82a7b2bcd2
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.0.0.
|
|
1
|
+
2.0.0.beta3
|
|
@@ -184,6 +184,39 @@ class RESTFramework::Serializers::NativeSerializer < RESTFramework::Serializers:
|
|
|
184
184
|
(ref.klass.method_defined?(field) && !ref.klass.reflect_on_association(field.to_sym))
|
|
185
185
|
end
|
|
186
186
|
|
|
187
|
+
# Recursively translate an association's fields into a `serializable_hash` config
|
|
188
|
+
# (`only`/`methods`/`include`). Columns go to `only` and plain methods to `methods`; a field that
|
|
189
|
+
# is itself an association is recursed into (as a nested `include`) only when it has its own entry
|
|
190
|
+
# in `field_config[:field_config]`. Otherwise it falls through to a method and serializes as
|
|
191
|
+
# before (its full `as_json`), so deeper nesting is opt-in and never narrows the default output.
|
|
192
|
+
def _build_association_config(model, fields, field_config)
|
|
193
|
+
nested = field_config[:field_config] || {}
|
|
194
|
+
only = []
|
|
195
|
+
methods = []
|
|
196
|
+
includes = {}
|
|
197
|
+
|
|
198
|
+
fields.each do |sf|
|
|
199
|
+
sf = sf.to_s
|
|
200
|
+
sub_field_config = nested[sf.to_sym] || nested[sf]
|
|
201
|
+
|
|
202
|
+
if sf.in?(model.column_names)
|
|
203
|
+
only << sf
|
|
204
|
+
elsif sub_field_config && (ref = model.reflect_on_association(sf.to_sym)) && !ref.polymorphic?
|
|
205
|
+
sub_fields = sub_field_config[:fields]&.map(&:to_s) ||
|
|
206
|
+
RESTFramework::Utils.association_fields_for(ref)
|
|
207
|
+
includes[sf] = self._build_association_config(ref.klass, sub_fields, sub_field_config)
|
|
208
|
+
elsif model.method_defined?(sf)
|
|
209
|
+
methods << sf
|
|
210
|
+
else
|
|
211
|
+
only << sf
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
config = { only: only, methods: methods }
|
|
216
|
+
config[:include] = includes if includes.any?
|
|
217
|
+
config
|
|
218
|
+
end
|
|
219
|
+
|
|
187
220
|
# Get a serializer configuration from the controller. `@controller` and `@model` must be set.
|
|
188
221
|
def _get_controller_serializer_config
|
|
189
222
|
columns = []
|
|
@@ -208,16 +241,13 @@ class RESTFramework::Serializers::NativeSerializer < RESTFramework::Serializers:
|
|
|
208
241
|
if f.in?(column_names)
|
|
209
242
|
columns << f
|
|
210
243
|
elsif ref = reflections[f]
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
sub_methods << sf
|
|
218
|
-
end
|
|
244
|
+
effective_fields = self._effective_association_fields(f, ref, field_config)
|
|
245
|
+
sub_config = if ref.polymorphic?
|
|
246
|
+
# No single target class to introspect, so serialize every field as a method.
|
|
247
|
+
{ only: [], methods: effective_fields }
|
|
248
|
+
else
|
|
249
|
+
self._build_association_config(ref.klass, effective_fields, field_config)
|
|
219
250
|
end
|
|
220
|
-
sub_config = { only: sub_columns, methods: sub_methods }
|
|
221
251
|
|
|
222
252
|
# Apply certain rules regarding collection associations.
|
|
223
253
|
if ref.collection?
|
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: 2.0.0.
|
|
4
|
+
version: 2.0.0.beta3
|
|
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: 2026-
|
|
11
|
+
date: 2026-08-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|