Sitelet https://github.com/jsonapi-serializer/jsonapi-serializer/issues/202
Skip to content

Running method on object being serialized once #202

Description

@asadakbarml

Expected Behavior

I am trying to find a way to run decorate on the object being serialized once instead of each time I use the object in an attribute definition. Ultimately I am looking for access to the object prior to any attribute methods being called.

Actual Behavior

Currently I have to call decorate multiple times instead of once for all attribute definitions:

attribute :full_name do |object|
  object.decorate.full_name
end

attribute :phone_numbers |object|
  object.decorate.phone_numbers
end

Steps to Reproduce the Problem

  1. Define a serializer
  2. Call decorate in each attribute definition block
  3. Performance degrades

Specifications

  • Version: 2.2.0
  • Ruby version: 2.5.8

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions