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
Add ‘object` accessor to be compatible with `ActiveModel::Serializer`.
Class Method Summary collapse
-
.cache_enabled? ⇒ Boolean
For compatibility with ‘active_model_serializers`.
-
.fragment_cache_enabled? ⇒ Boolean
For compatibility with ‘active_model_serializers`.
Instance Method Summary collapse
-
#associations(*args, **kwargs) ⇒ Object
For compatibility with ‘active_model_serializers`.
-
#initialize(object = nil, *args, controller: nil, **kwargs) ⇒ BaseSerializer
constructor
Accept/ignore ‘*args` to be compatible with the `ActiveModel::Serializer#initialize` signature.
-
#serializable_hash(*args) ⇒ Object
Synonym for ‘serialize` for compatibility with `active_model_serializers`.
-
#serialize(*args) ⇒ Object
The primary interface for extracting a native Ruby types.
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
#object ⇒ Object
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`.
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`.
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`.
14 15 16 |
# File 'lib/rest_framework/serializers.rb', line 14 def serialize(*args) raise NotImplementedError end |