Sha256: d02e868ad920cc99696c861e42098b5dcf088e4189429b83d54e2d630e36220d

Contents?: true

Size: 723 Bytes

Versions: 3

Compression:

Stored size: 723 Bytes

Contents

# frozen_string_literal: true

require "dato/json_api_serializer"

module Dato
  module Utils
    module BuildModularBlock
      def self.build(unserialized_body)
        json_api_serializer = JsonApiSerializer.new(type: "item")
        attributes = json_api_serializer.serialized_attributes(unserialized_body)

        payload = {
          type: "item",
          attributes: attributes,
          relationships: {
            item_type: {
              data: {
                id: unserialized_body[:item_type],
                type: "item_type",
              },
            },
          },
        }

        payload[:id] = unserialized_body[:id] if unserialized_body[:id]

        payload
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dato-0.8.3 lib/dato/utils/build_modular_block.rb
dato-0.8.2 lib/dato/utils/build_modular_block.rb
dato-0.8.1 lib/dato/utils/build_modular_block.rb