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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 639dcc597e17e5148cde3f7511637913be7b431899f59a5cc7f504533969233e
4
- data.tar.gz: 0c732ab6c80f9c06b29e4a30e29087ff4fa65206df15b7826ffd9f0d2781b774
3
+ metadata.gz: 7cedfa02dac90388b712f4e15e29d07a40e45df23847bebf5da02eea03862e75
4
+ data.tar.gz: 2de9c962810e9473dd5eb68c2ee42da764ed793e341049a49d9f4ca8d34fa48e
5
5
  SHA512:
6
- metadata.gz: 656e302db2252a27a30508e1f5c1d2caf2d603288d4ca3e2ec0995355a4a6501b18bc8320463a17113568a562ead98c3896c949a00aa03cc83a6c71f2f62d738
7
- data.tar.gz: f760d0140360ca1856dca0ab87b8de1903e09fd7cc442c1b40c9150b7abaf312f43ae67a52a5d0881af9e1f98489a074a82ebaef87b527c99e6e8f7175c67740
6
+ metadata.gz: f52b1b1075fef181d9e771df56f1c088c73601d600606411974febb1bb544facacc7d16d83c2b34929acc0d0f44a0e518098a3a121fcdf27f7e5f12be3a5d8ca
7
+ data.tar.gz: c08ffc3af87bb7d7337dd1a908c7c6199fa3e70328b06dbebd1a691a0c3f235224b0119026eda4274f555385254383d2a7a29719b339f5c487f0ee82a7b2bcd2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta2
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
- sub_columns = []
212
- sub_methods = []
213
- self._effective_association_fields(f, ref, field_config).each do |sf|
214
- if !ref.polymorphic? && sf.in?(ref.klass.column_names)
215
- sub_columns << sf
216
- else
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.beta2
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-07-31 00:00:00.000000000 Z
11
+ date: 2026-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails