Last active
December 15, 2022 04:13
-
-
Save am-kantox/288db2e1ba0d4eaee7b3aa70eeee4ca4 to your computer and use it in GitHub Desktop.
Behaviour Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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