Class: RESTFramework::BaseSerializer
- Inherits:
-
Object
- Object
- RESTFramework::BaseSerializer
- Defined in:
- lib/rest_framework/serializers.rb
Overview
The base serializer defines the interface for all REST Framework serializers.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
-
#initialize(object = nil, controller: nil, **kwargs) ⇒ BaseSerializer
constructor
A new instance of BaseSerializer.
-
#serializable_hash(**kwargs) ⇒ Object
Synonym for ‘serializable_hash` or compatibility with ActiveModelSerializers.
-
#serialize(**kwargs) ⇒ Object
The primary interface for extracting a native Ruby types.
Constructor Details
#initialize(object = nil, controller: nil, **kwargs) ⇒ BaseSerializer
Returns a new instance of BaseSerializer.
5 6 7 8 |
# File 'lib/rest_framework/serializers.rb', line 5 def initialize(object=nil, controller: nil, **kwargs) @object = object @controller = controller end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
3 4 5 |
# File 'lib/rest_framework/serializers.rb', line 3 def object @object end |
Instance Method Details
#serializable_hash(**kwargs) ⇒ Object
Synonym for ‘serializable_hash` or compatibility with ActiveModelSerializers.
17 18 19 |
# File 'lib/rest_framework/serializers.rb', line 17 def serializable_hash(**kwargs) return self.serialize(**kwargs) end |
#serialize(**kwargs) ⇒ Object
The primary interface for extracting a native Ruby types. This works both for records and collections.
12 13 14 |
# File 'lib/rest_framework/serializers.rb', line 12 def serialize(**kwargs) raise NotImplementedError end |