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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object = nil, *args, controller: nil, **kwargs) ⇒ BaseSerializer

Accept/ignore ‘*args` to be compatible with the `ActiveModel::Serializer#initialize` signature.



7
8
9
10
# File 'lib/rest_framework/serializers.rb', line 7

def initialize(object=nil, *args, controller: nil, **kwargs)
  @object = object
  @controller = controller
end

Instance Attribute Details

#objectObject

Add ‘object` accessor to be compatible with `ActiveModel::Serializer`.



4
5
6
# File 'lib/rest_framework/serializers.rb', line 4

def object
  @object
end

Class Method Details

.cache_enabled?Boolean

For compatibility with ‘active_model_serializers`.

Returns:

  • (Boolean)


24
25
26
# File 'lib/rest_framework/serializers.rb', line 24

def self.cache_enabled?
  return false
end

.fragment_cache_enabled?Boolean

For compatibility with ‘active_model_serializers`.

Returns:

  • (Boolean)


29
30
31
# File 'lib/rest_framework/serializers.rb', line 29

def self.fragment_cache_enabled?
  return false
end

Instance Method Details

#associations(*args, **kwargs) ⇒ Object

For compatibility with ‘active_model_serializers`.



34
35
36
# File 'lib/rest_framework/serializers.rb', line 34

def associations(*args, **kwargs)
  return []
end

#serializable_hash(*args) ⇒ Object

Synonym for ‘serialize` for compatibility with `active_model_serializers`.



19
20
21
# File 'lib/rest_framework/serializers.rb', line 19

def serializable_hash(*args)
  return self.serialize(*args)
end

#serialize(*args) ⇒ Object

The primary interface for extracting a native Ruby types. This works both for records and collections. We accept and ignore ‘*args` for compatibility with `active_model_serializers`.

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/rest_framework/serializers.rb', line 14

def serialize(*args)
  raise NotImplementedError
end