From 4d4ebbf1cab5d70493b262919e40c9ab3ef3e0b1 Mon Sep 17 00:00:00 2001 From: nduitz Date: Mon, 6 Jul 2020 09:46:11 +0200 Subject: [PATCH 1/2] make tracked? overridable --- lib/repo/repo.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/repo/repo.ex b/lib/repo/repo.ex index 02a7851..c0005f3 100644 --- a/lib/repo/repo.ex +++ b/lib/repo/repo.ex @@ -57,7 +57,7 @@ defmodule ExAudit.Repo do delete!: 2 ) - defp tracked?(struct_or_changeset) do + def tracked?(struct_or_changeset) do tracked_schemas = Application.get_env(:ex_audit, :tracked_schemas, []) schema = @@ -74,6 +74,8 @@ defmodule ExAudit.Repo do @compile {:inline, tracked?: 1} + defoverridable(tracked?: 1) + def insert(struct, opts) do if tracked?(struct) do ExAudit.Schema.insert( From ccdcd10921b5182e85e0b60d0e8f1b8f64379e80 Mon Sep 17 00:00:00 2001 From: nduitz Date: Mon, 6 Jul 2020 10:28:55 +0200 Subject: [PATCH 2/2] add some documentation --- lib/repo/repo.ex | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/repo/repo.ex b/lib/repo/repo.ex index c0005f3..068bb74 100644 --- a/lib/repo/repo.ex +++ b/lib/repo/repo.ex @@ -57,6 +57,23 @@ defmodule ExAudit.Repo do delete!: 2 ) + @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, [])