Sha256: 78f68ce4acef3e93acbb9cd9ede00806c999620d6e994e8b1ef449f508c47a3c

Contents?: true

Size: 1.27 KB

Versions: 13

Compression:

Stored size: 1.27 KB

Contents

module ActiveModelSerializers
  module Adapter
    class JsonApi < Base
      # {http://jsonapi.org/format/#document-jsonapi-object Jsonapi Object}

      # 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
      module Jsonapi
        module_function

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

        def include_object?
          ActiveModelSerializers.config.jsonapi_include_toplevel_object
        end

        # TODO: see if we can cache this
        def object
          object = {
            jsonapi: {
              version: ActiveModelSerializers.config.jsonapi_version,
              meta: ActiveModelSerializers.config.jsonapi_toplevel_meta
            }
          }
          object[:jsonapi].reject! { |_, v| v.blank? }

          object
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
active_model_serializers-0.10.8 lib/active_model_serializers/adapter/json_api/jsonapi.rb
active_model_serializers-0.10.7 lib/active_model_serializers/adapter/json_api/jsonapi.rb
active_model_serializers-0.10.6 lib/active_model_serializers/adapter/json_api/jsonapi.rb
active_model_serializers-0.10.5 lib/active_model_serializers/adapter/json_api/jsonapi.rb
active_model_serializers-0.10.4 lib/active_model_serializers/adapter/json_api/jsonapi.rb
agi_active_model_serializers-0.10.9 lib/active_model_serializers/adapter/json_api/jsonapi.rb
agi_active_model_serializers-0.10.8 lib/active_model_serializers/adapter/json_api/jsonapi.rb
agi_active_model_serializers-0.10.7 lib/active_model_serializers/adapter/json_api/jsonapi.rb
active_model_serializers-0.10.3 lib/active_model_serializers/adapter/json_api/jsonapi.rb
active_model_serializers-0.10.2 lib/active_model_serializers/adapter/json_api/jsonapi.rb
active_model_serializers-0.10.1 lib/active_model_serializers/adapter/json_api/jsonapi.rb
active_model_serializers-0.10.0 lib/active_model_serializers/adapter/json_api/jsonapi.rb
active_model_serializers-0.10.0.rc5 lib/active_model_serializers/adapter/json_api/jsonapi.rb