rest_framework 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58fa867a9eed508be6ef78687d445cb5f3c0dc8cf0c004d8a8eab7f003f622cb
4
- data.tar.gz: da285af9bf75273dcd864362d57ada399cc876e0e28767e546a89d1a8f280d28
3
+ metadata.gz: 68ebf30c14f9f70796c6963505e7b45421ee838d076784073505feb9b05c3ddb
4
+ data.tar.gz: 71918c4b2b2eeaed10833d84cb54f6bbb860ea3205895bc75abf9a543d0bedc9
5
5
  SHA512:
6
- metadata.gz: 480e49357afb571538b0f5ec730eff04a0dc326ca4d9e93e9bbba7a60571c3dc2b09ddd3cbfa4ca2dec734e4de5de6faec542e5d06d5e9674e2c492575d2b450
7
- data.tar.gz: 138e532ede2fdd207a557edf0cc8fd89f24eceb782b251adf107c3e445ad2e0a32d69fa66475d1215321f6085a953cce98f586284e39d207d453727e66f8a714
6
+ metadata.gz: d909e86567107d2565a65e9c99f67b771e462a2bd9dae04289c9846cc0ba68bfe3728b63d1b8a154c532e7a5cb1aeac1f593401a98bbc0b1f405f474aabb8527
7
+ data.tar.gz: abe06a65bb999c4926e6a54295afc4c55e254fba1276b0257eb2af765bbc3f367fe5ebc5d9fe1d6181c45157369440de13a7f4aed331a49271426d2468110a99
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.4
1
+ 0.6.5
@@ -90,6 +90,12 @@ module RESTFramework::BaseControllerMixin
90
90
  def get_serializer_class
91
91
  return nil unless serializer_class = self.class.serializer_class
92
92
 
93
+ # Support dynamically resolving serializer given a symbol or string.
94
+ serializer_class = serializer_class.to_s if serializer_class.is_a?(Symbol)
95
+ if serializer_class.is_a?(String)
96
+ serializer_class = self.class.const_get(serializer_class)
97
+ end
98
+
93
99
  # Wrap it with an adapter if it's an active_model_serializer.
94
100
  if defined?(ActiveModel::Serializer) && (serializer_class < ActiveModel::Serializer)
95
101
  serializer_class = RESTFramework::ActiveModelSerializerAdapterFactory.for(serializer_class)
@@ -114,6 +114,11 @@ module RESTFramework::BaseModelControllerMixin
114
114
  return super || RESTFramework::NativeSerializer
115
115
  end
116
116
 
117
+ # Helper to serialize data using the `serializer_class`.
118
+ def serialize(data, **kwargs)
119
+ return self.get_serializer_class.new(data, controller: self, **kwargs).serialize
120
+ end
121
+
117
122
  # Helper to get filtering backends, defaulting to using `ModelFilter` and `ModelOrderingFilter`.
118
123
  def get_filter_backends
119
124
  return self.class.filter_backends || [
@@ -232,10 +237,10 @@ module RESTFramework::ListModelMixin
232
237
  if self.class.paginator_class
233
238
  paginator = self.class.paginator_class.new(data: @records, controller: self)
234
239
  page = paginator.get_page
235
- serialized_page = self.get_serializer_class.new(page, controller: self).serialize
240
+ serialized_page = self.serialize(page)
236
241
  return paginator.get_paginated_response(serialized_page)
237
242
  else
238
- return self.get_serializer_class.new(@records, controller: self).serialize
243
+ return self.serialize(@records)
239
244
  end
240
245
  end
241
246
  end
@@ -248,7 +253,7 @@ module RESTFramework::ShowModelMixin
248
253
 
249
254
  def show!
250
255
  @record ||= self.get_record
251
- return self.get_serializer_class.new(@record, controller: self).serialize
256
+ return self.serialize(@record)
252
257
  end
253
258
  end
254
259
 
@@ -269,7 +274,7 @@ module RESTFramework::CreateModelMixin
269
274
  @record ||= self.get_model.create!(self.get_create_params)
270
275
  end
271
276
 
272
- return self.get_serializer_class.new(@record, controller: self).serialize
277
+ return self.serialize(@record)
273
278
  end
274
279
  end
275
280
 
@@ -282,7 +287,7 @@ module RESTFramework::UpdateModelMixin
282
287
  def update!
283
288
  @record ||= self.get_record
284
289
  @record.update!(self.get_update_params)
285
- return self.get_serializer_class.new(@record, controller: self).serialize
290
+ return self.serialize(@record)
286
291
  end
287
292
  end
288
293
 
@@ -282,21 +282,6 @@ class RESTFramework::NativeSerializer < RESTFramework::BaseSerializer
282
282
  end
283
283
  end
284
284
 
285
- # :nocov:
286
- # Alias NativeModelSerializer -> NativeSerializer.
287
- class RESTFramework::NativeModelSerializer < RESTFramework::NativeSerializer
288
- def initialize(**kwargs)
289
- super
290
- ActiveSupport::Deprecation.warn(
291
- <<~MSG.split("\n").join(" "),
292
- RESTFramework::NativeModelSerializer is deprecated and will be removed in future versions of
293
- REST Framework; you should use RESTFramework::NativeSerializer instead.
294
- MSG
295
- )
296
- end
297
- end
298
- # :nocov:
299
-
300
285
  # This is a helper factory to wrap an ActiveModelSerializer to provide a `serialize` method which
301
286
  # accepts both collections and individual records. Use `.for` to build adapters.
302
287
  class RESTFramework::ActiveModelSerializerAdapterFactory
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
4
+ version: 0.6.5
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-10-10 00:00:00.000000000 Z
11
+ date: 2022-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails