Class: RESTFramework::BaseSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/rest_framework/serializers.rb

Overview

The base serializer defines the interface for all REST Framework serializers.

Direct Known Subclasses

NativeSerializer

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#objectObject

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.

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/rest_framework/serializers.rb', line 12

def serialize(**kwargs)
  raise NotImplementedError
end