Packages
Elixir implementation of the NLdoc Spec for events from conversion of documents.
Current section
Files
Jump to
Current section
Files
lib/nldoc/spec/event/progress.ex
defmodule NLdoc.Spec.Event.Progress do
@moduledoc """
This module defines the Ecto schema for the NLdoc Event 'progress'.
"""
use NLdoc.SpecDef.Schema, type: "https://event.spec.nldoc.nl/progress"
defmodule Context do
@moduledoc false
use NLdoc.SpecDef.Schema, type: nil
typed_embedded_schema null: false do
field :subject, Ecto.Enum, values: [:page, :document]
field :target, :integer
field :position, :integer
end
def changeset(object, attrs) do
fields = [:subject, :target, :position]
object
|> cast(attrs, fields, @cast_opts)
|> validate_required(fields)
|> validate_number(:target, greater_than_or_equal_to: 1)
|> validate_number(:position, greater_than_or_equal_to: 0)
end
end
typed_embedded_schema null: false do
field :type, :string, default: @resource_type
field :timestamp, :utc_datetime
field :trace_id, :string
embeds_one :context, Context
end
def changeset(object, attrs) do
fields = [:type, :timestamp, :trace_id]
object
|> cast(attrs, fields, @cast_opts)
|> cast_embed(:context)
|> validate_required([:context] ++ fields)
|> validate_inclusion(:type, [@resource_type])
end
end