Skip to content

Instantly share code, notes, and snippets.

@am-kantox
Last active December 15, 2022 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save am-kantox/288db2e1ba0d4eaee7b3aa70eeee4ca4 to your computer and use it in GitHub Desktop.
Save am-kantox/288db2e1ba0d4eaee7b3aa70eeee4ca4 to your computer and use it in GitHub Desktop.
Behaviour Example
defmodule Tracker do
@moduledoc """
The `Tracker` behaviour declaring the interface for tracker backend.
"""
@doc """
The function to be called from tracked entity.
"""
@callback track(binary(), any()) :: :ok
@tracker Application.compile_env(:my_app, :tracker_backend, Tracker.Default)
@doc "Router to the implementation"
def track(uuid, entity), do: @tracker.track(uuid, entity)
end
defmodule Tracker.Default do
@moduledoc false
require Logger
@behaviour Tracker
@impl Tracker
def track(uuid, entity), do: Logger.info(uuid <> ": " <> inspect(entity))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment