Gut.Subject protocol (gut v0.2.0)

Copy Markdown View Source

Converts a subject into the value that Gut sends to an adapter.

The result is the text sent to the adapter. Gut sends strings unchanged and encodes other values as JSON.

Derive this protocol to choose which struct fields Gut can send:

defmodule Ticket do
  @derive {Gut.Subject, only: [:subject, :body]}
  defstruct [:subject, :body, :internal_notes]
end

Derivation accepts :only or :except. Prefer :only so new fields are not exposed by accident. A derivation without options includes every struct field.

Implement the protocol directly when a subject needs a custom representation.

Summary

Types

t()

All the types that implement this protocol.

Functions

Returns the text sent as the subject.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

to_text(subject)

@spec to_text(t()) :: String.t()

Returns the text sent as the subject.