Trogon.TypeProvider (Trogon.TypeProvider v0.2.2)

View Source

Provides a type mapping system for converting between string type names and Elixir struct modules.

Summary

Functions

Imports all the types from another module defined by Trogon.TypeProvider.

Registers a mapping from a type string to an Elixir Module that defines a struct.

Functions

import_type_provider(provider_mod)

(macro)
@spec import_type_provider(provider_mod :: module()) :: Macro.t()

Imports all the types from another module defined by Trogon.TypeProvider.

Example

defmodule UserTypeProvider do
  use Trogon.TypeProvider
  # ...
end

defmodule MyAppTypeProvider do
  use Trogon.TypeProvider

  import_type_provider UserTypeProvider
end

register_type(type, struct_mod)

(macro)
@spec register_type(type :: String.t(), struct_mod :: module()) :: Macro.t()

Registers a mapping from a type string to an Elixir Module that defines a struct.

Example

defmodule MyTypeProvider do
  use Trogon.TypeProvider,
    prefix: "accounts." # optional, adds the prefix to the type

  register_type "account_created", AccountCreated
end