Rill v0.10.4 Rill.Messaging.Message.Dictionary behaviour View Source

Converts messages from database representation to the related struct

Link to this section Summary

Types

t()

Used as a dictionary to convert a type name (text) into its related module

Functions

Provides def macro and sets up dictionary callback

Defines a function and appends the type of the first argument (must be a struct) to the dictionary of the module

Link to this section Types

Link to this type

t() View Source
t() :: %Rill.Messaging.Message.Dictionary{
  type_names: %{optional(String.t()) => module()}
}

Used as a dictionary to convert a type name (text) into its related module

Link to this section Functions

Link to this macro

__using__(opts \\ []) View Source (macro)

Provides def macro and sets up dictionary callback

Link to this macro

def(head, list) View Source (macro)

Defines a function and appends the type of the first argument (must be a struct) to the dictionary of the module.

Examples

defmodule Foo.Bar do
  defstruct [:name, :age]
end

defmodule Projection do
  alias Foo.Bar

  def apply(%Bar{} = bar, entity) do
    # ...
  end
end

Rill.Message.Dictionary.get_dictionary(Projection)
# %Projection{type_names: %{"Bar" => Foo.Bar}}
Link to this function

get_dictionary(module) View Source
get_dictionary(module :: module()) :: %Rill.Messaging.Message.Dictionary{
  type_names: term()
}

Link to this function

translate(module, message_data) View Source
translate(
  module :: module(),
  message_data :: %Rill.MessageStore.MessageData.Read{
    data: term(),
    global_position: term(),
    id: term(),
    metadata: term(),
    position: term(),
    stream_name: term(),
    time: term(),
    type: term()
  }
) :: nil | struct()
translate(
  dictionary :: %Rill.Messaging.Message.Dictionary{type_names: term()},
  message_data :: %Rill.MessageStore.MessageData.Read{
    data: term(),
    global_position: term(),
    id: term(),
    metadata: term(),
    position: term(),
    stream_name: term(),
    time: term(),
    type: term()
  }
) :: nil | struct()

Link to this function

translate_name(dictionary, type) View Source
translate_name(
  dictionary :: %Rill.Messaging.Message.Dictionary{type_names: term()},
  type :: String.t()
) :: nil | module()

Link to this section Callbacks

Link to this callback

dictionary() View Source
dictionary() :: %Rill.Messaging.Message.Dictionary{type_names: term()}