Class: Decidim::Exporters::Serializer

Inherits:
Object
  • Object
show all
Defined in:
app/serializers/decidim/exporters/serializer.rb

Overview

This is an abstract class with a very naive default implementation for the exporters to use. It can also serve as a superclass of your own implementation.

It is used to be run against each element of an exportable collection in order to extract relevant fields. Every export should specify their own serializer or this default will be used.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Serializer

Initializes the serializer with a resource.

resource - The Object to serialize.



18
19
20
# File 'app/serializers/decidim/exporters/serializer.rb', line 18

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



13
14
15
# File 'app/serializers/decidim/exporters/serializer.rb', line 13

def resource
  @resource
end

Instance Method Details

#serializeObject

Public: Returns a serialized view of the provided resource.

Returns a nested Hash with the fields.



25
26
27
# File 'app/serializers/decidim/exporters/serializer.rb', line 25

def serialize
  @resource.to_h
end