From f15cb040becf52f8e2cb93f21fb2956e53ff75a6 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 4 May 2017 12:24:07 +0200 Subject: Copyedit documentation about using serializers --- app/serializers/README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/serializers/README.md b/app/serializers/README.md index d870d08d70b..26d27d37fe4 100644 --- a/app/serializers/README.md +++ b/app/serializers/README.md @@ -5,15 +5,15 @@ This is a documentation for classes located in `app/serializers` directory. In GitLab, we use [grape-entities][grape-entity-project], accompanied by a serializer, to convert a Ruby object to its JSON representation. -Serializers are typically used in a controllers to build a JSON response +Serializers are typically used in controllers to build a JSON response that is usually consumed by a frontend code. ## What is a serializer? -Serializer is a class that encapsulates all business rules for building a JSON -response using serialization entities. +A serializer is a class that encapsulates all business rules for building a +JSON response using serialization entities. -## What are serialization entities? +## What is a serialization entity? Entities are a lightweight structures that allow to represent domain models in a consistent and abstracted way, and reuse them as a building blocks to @@ -22,7 +22,7 @@ create a payload. Entities located in `app/serializers` are usually derived from a [`Grape::Entity`][grape-entity] class. -Serialization entities that do require a to have a knowledge about specific +Serialization entities that do require to have a knowledge about specific elements of the request, need to mix `RequestAwareEntity` in. ## How to implement a serializer? @@ -34,5 +34,8 @@ class in `app/serializers`. See existing serializers for an example. ## How to use serializer in a controller? +## Best practices + [grape-entity-project]: https://github.com/ruby-grape/grape-entity [grape-entity-class]: https://github.com/ruby-grape/grape-entity/blob/master/lib/grape_entity/entity.rb + -- cgit v1.2.1