Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use different values per type #25

Open
prodis opened this issue Oct 7, 2022 · 3 comments
Open

Option to use different values per type #25

prodis opened this issue Oct 7, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@prodis
Copy link

prodis commented Oct 7, 2022

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?

@prodis prodis added the enhancement New feature or request label Oct 7, 2022
@prodis prodis changed the title Option to use different values for type Option to use different values per type Oct 7, 2022
@quaresc
Copy link
Contributor

quaresc commented Oct 19, 2022

Hello @prodis ! Thank you for your suggestion !
Indeed that could be useful ! But maybe I would see that more in a config file to override default type values instead of putting it in a each schemas

What do you think ? :)

@prodis
Copy link
Author

prodis commented Oct 19, 2022

That is an interesting idea. Shall I open a PR with an implementation proposal?

@quaresc
Copy link
Contributor

quaresc commented Oct 19, 2022

Sure with pleasure ! 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants