Current section

Files

Jump to
nldoc_spec lib nldoc spec block_quotation.ex
Raw

lib/nldoc/spec/block_quotation.ex

defmodule NLdoc.Spec.BlockQuotation do
@moduledoc """
This module defines the Ecto schema for the NLdoc spec BlockQuotation object.
"""
use NLdoc.Spec.Schema, type: "https://spec.nldoc.nl/Resource/BlockQuotation"
alias NLdoc.Spec.Paragraph
typed_embedded_schema null: false do
field :id, Ecto.UUID
field :type, :string, default: @resource_type
field :cite, :string, null: true
embeds_many :caption, Paragraph
field(:children, {:array, PolymorphicEmbed},
types: map(NLdoc.Spec.blockquote_children()),
type_field_name: :type,
on_replace: :delete,
default: [],
array?: true
) :: [NLdoc.Spec.blockquote_child()]
field(:descriptors, {:array, PolymorphicEmbed},
types: map(NLdoc.Spec.descriptors()),
type_field_name: :type,
on_replace: :delete,
default: [],
array?: true
) :: [NLdoc.Spec.descriptor()]
end
def changeset(object, attrs) do
object
|> cast(attrs, [:id, :type, :cite], @cast_opts)
|> cast_embed(:caption, @cast_opts)
|> cast_polymorphic_embed(:children, @cast_opts)
|> cast_polymorphic_embed(:descriptors, @cast_opts)
|> validate_required([:id, :type])
|> validate_inclusion(:type, [@resource_type])
end
end