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



28
29
30
# File 'lib/active_model_serializers/adapter/json_api/jsonapi.rb', line 28

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

.include_object?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/active_model_serializers/adapter/json_api/jsonapi.rb', line 32

def include_object?
  ActiveModelSerializers.config.jsonapi_include_toplevel_object
end

.objectObject

TODO: see if we can cache this



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

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

  object
end