-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Currently it is only possible to anonymise a field with a value different from the default value providing a custom function for each field.
For example:
defmodule User do
use Ecto.Schema
use EctoAnon.Schema
anon_schema [
name: &__MODULE__.custom_string/3
email: &__MODULE__.custom_string/3
]
schema "users" do
field :name, :string
field :age, :integer
field :email, :string
anonymized()
end
def custom_string(:string, %__MODULE__{} = _user, _opts \\ []), do: "[REDACTED]"
end
user = Repo.get(User, id)
%User{name: "jane", age: 24, email: "[email protected]"}
EctoAnon.run(user, Repo)
{:ok, %User{name: "[REDACTED]", age: 24, email: "[REDACTED]"}}My suggestion is to have an alternative to provider a different value per type.
For example:
defmodule User do
use Ecto.Schema
use EctoAnon.Schema
anon_schema(
[:name, :email],
anonymized_values: [string: "[REDACTED]"]
)
schema "users" do
field :name, :string
field :age, :integer
field :email, :string
anonymized()
end
end
user = Repo.get(User, id)
%User{name: "jane", age: 24, email: "[email protected]"}
EctoAnon.run(user, Repo)
{:ok, %User{name: "[REDACTED]", age: 24, email: "[REDACTED]"}}I am not thinking about the implementation details now, only the public interface and its usage for the sake of the discussion of the new feature. 🙂
What do you think?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request