Hydrex.Hydratable.Utils (hydrex v0.1.2)

Utility functions for hydrating Ecto structs with virtual fields.

Summary

Functions

Conditionally hydrates the given data.

Functions

maybe_hydrate(data, opts)

@spec maybe_hydrate(any(), boolean() | keyword()) :: any()

Conditionally hydrates the given data.

Parameters

  • data: The Ecto struct or a list of structs to hydrate.
  • opts: Options to control hydration. If true, all virtual fields will be hydrated. If false, no virtual fields will be hydrated. If a keyword list is provided, hydration will occur if :hydrate is true 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]])