Sha256: a97c7814d0c11c81298cc31fff507d9243c36b3272459f3f4e834402c4f5c545

Contents?: true

Size: 554 Bytes

Versions: 1

Compression:

Stored size: 554 Bytes

Contents

# frozen_string_literal: true

require 'active_support/core_ext/hash/keys'

module JSONAPIHelpers
  module Serializers
    class Relationships
      def initialize
        @relationships = {}
      end

      def add(relation:, id:, type:)
        @relationships[relation] = { id: id, type: type }
      end

      def to_h
        @relationships
      end

      # Rails is awkward and calls #to_json with a context argument
      # NOTE: Rails only method Hash#to_json
      def to_json(_context = nil)
        to_h.to_json
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jsonapi_helpers-0.2.0 lib/jsonapi_helpers/serializers/relationships.rb