Hydrex.Hydratable.Utils (hydrex v0.1.2)
Utility functions for hydrating Ecto structs with virtual fields.
Summary
Functions
Conditionally hydrates the given data.
Functions
Conditionally hydrates the given data.
Parameters
data
: The Ecto struct or a list of structs to hydrate.opts
: Options to control hydration. Iftrue
, all virtual fields will be hydrated. Iffalse
, no virtual fields will be hydrated. If a keyword list is provided, hydration will occur if:hydrate
istrue
or a list of virtual fields must be provided.
Examples
iex> import Hydrex.Hydratable.Utils, only: [maybe_hydrate: 2]
iex> my_url = %MyApp.Url{link: "https://example.com"}
iex> maybe_hydrate(my_url, true)
iex> maybe_hydrate(my_url, [hydrate: true])
iex> maybe_hydrate(my_url, [hydrate: [:is_safe]])