Module: ActiveModelSerializers::Adapter::JsonApi::Jsonapi

Defined in:
lib/active_model_serializers/adapter/json_api/jsonapi.rb

Overview

toplevel_jsonapi definition:

JSON Object

properties:

version : String
meta

description:

An object describing the server's implementation

structure:

{
  version: ActiveModelSerializers.config.jsonapi_version,
  meta: ActiveModelSerializers.config.jsonapi_toplevel_meta
}.reject! { |_, v| v.blank? }

prs:

https://github.com/rails-api/active_model_serializers/pull/1050

Class Method Summary collapse

Class Method Details

.add!(hash) ⇒ Object


26
27
28
# File 'lib/active_model_serializers/adapter/json_api/jsonapi.rb', line 26

def add!(hash)
  hash.merge!(object) if include_object?
end

.include_object?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'lib/active_model_serializers/adapter/json_api/jsonapi.rb', line 30

def include_object?
  ActiveModelSerializers.config.jsonapi_include_toplevel_object
end

.objectObject

TODO: see if we can cache this


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_model_serializers/adapter/json_api/jsonapi.rb', line 35

def object
  object = {
    jsonapi: {
      version: ActiveModelSerializers.config.jsonapi_version,
      meta: ActiveModelSerializers.config.jsonapi_toplevel_meta
    }
  }
  object[:jsonapi].reject! { |_, v| v.blank? }

  object
end