API Docs for: 1.0.0-beta.4
Show:

DS.UnderscoredSerializer Class

The UnderscoredSerializer is intended use when creating a subclass of the DS.RESTSerializer.

Based on activemodel-adapter package, supports hasMany and belongsTo records embedded in JSON payloads, designed to work out of the box with the active_model_serializers Ruby gem. And is designed to integrate with an API that uses an underscored naming convention instead of camelCasing.

Constructor

DS.UnderscoredSerializer

()

Methods

keyForAttribute

(
  • attribute
)

Converts camelCased attributes to underscored when serializing.

Parameters:

  • attribute String

Returns:

String

keyForRelationship

(
  • key
  • kind
)

Underscores relationship names and appends "_id" or "_ids" when serializing relationship keys.

Parameters:

  • key String
  • kind String

Returns:

String

normalize

(
  • type
  • hash
  • prop
)

Add extra step to DS.RESTSerializer.normalize so links are normalized.

If your payload looks like:

{
  "post": {
    "id": 1,
    "title": "Rails is omakase",
    "links": { "flagged_comments": "api/comments/flagged" }
  }
}

The normalized version would look like this

{
  "post": {
    "id": 1,
    "title": "Rails is omakase",
    "links": { "flaggedComments": "api/comments/flagged" }
  }
}

Parameters:

  • type subclass of DS.Model
  • hash Object
  • prop String

Returns:

Object

normalizeRelationships

() private

Normalize the polymorphic type from the JSON.

Normalize:

  {
    id: "1"
    minion: { type: "evil_minion", id: "12"}
  }

To:

  {
    id: "1"
    minion: { type: "evilMinion", id: "12"}
  }

serializeIntoHash

(
  • hash
  • type
  • record
  • options
)

Underscores the JSON root keys when serializing.

Parameters:

  • hash Object
  • type subclass of DS.Model
  • record DS.Model
  • options Object

serializePolymorphicType

(
  • record
  • json
  • relationship
)

Serializes a polymorphic type as a fully capitalized model name.

Parameters:

  • record DS.Model
  • json Object
  • relationship Object

typeForRoot

(
  • root
)

Extracts the model typeKey from underscored root objects.

Parameters:

  • root String

Returns:

String the model's typeKey