Skip to content

Commit

Permalink
Merge pull request ZennerIoT#52 from nduitz/defoverridable-tracked
Browse files Browse the repository at this point in the history
make tracked? overridable
  • Loading branch information
narrowtux authored Mar 10, 2021
2 parents aea7a19 + ccdcd10 commit 937918a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/repo/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,24 @@ defmodule ExAudit.Repo do
delete!: 2
)

defp tracked?(struct_or_changeset) do
@doc """
Decides based on config `tracked_schema` wether the current schema is tracked or not.
Can be overwritten for custom tracking logic.
E.g.
```
def tracked?(struct_or_schema) do
tracked? =
case Process.get(__MODULE__) do
%{tracked?: true} -> true
_ -> false
end
tracked? && super(struct_or_schema)
end
```
"""
def tracked?(struct_or_changeset) do
tracked_schemas = Application.get_env(:ex_audit, :tracked_schemas, [])

schema =
Expand All @@ -74,6 +91,8 @@ defmodule ExAudit.Repo do

@compile {:inline, tracked?: 1}

defoverridable(tracked?: 1)

def insert(struct, opts) do
if tracked?(struct) do
ExAudit.Schema.insert(
Expand Down

0 comments on commit 937918a

Please sign in to comment.