Feat: create generic `strip_struct_metadata` to remove surplus fields from `Struct`
- Dominant language
- Elixir
- Stars
- 36
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
At present we have a `strip_struct_metadata/1` function is hidden in:
https://github.com/dwyl/auth_plug/blob/da40aca75d5ecc0fc016023f4a61eb6f4b7cfb6f/lib/auth_plug_helpers.ex#L18C1-L33C6
```elixir
@doc """
`strip_struct_metadata/1` removes the Ecto Struct metadata from a struct.
This is essential before attempting to create a JWT as `Jason.encode/2`
chokes on any invalid data. See: github.com/dwyl/auth_plug/issues/16
"""
def strip_struct_metadata(struct) do
struct
|> Map.delete(:__meta__)
|> Map.delete(:__struct__)
# association
|> Map.delete(:statuses)
# association
|> Map.delete(:login_logs)
# binary
|> Map.delete(:email_hash)
end
```
We can _easily_ make this function _generic_ and reusable by accepting a second argument `field_list`.
# Todo
+ [ ] Create the tests (borrow from `auth_plug` and extend with `field_list`)
+ [ ] " function definition
+ [ ] " PR
+ [ ] Publish new version of package to `hex.pm`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.