CapsuleEcto v1.0.0 Capsule.Ecto View Source

Link to this section Summary

Functions

Processes an upload for each permitted field found in params, calling the given function to produce a Capsule.Locator and casting it onto the changeset.

Link to this section Types

Specs

changeset() :: Ecto.Changeset.t()

Specs

opts() :: [{:required, boolean()}]

Specs

params() :: map()

Specs

permitted() :: [atom()]

Link to this section Functions

Link to this function

upload(changeset, params, permitted, func, opts \\ [])

View Source

Specs

upload(
  changeset(),
  params(),
  permitted(),
  (tuple(), changeset() -> Capsule.Locator.t() | changeset()),
  opts()
) :: changeset()
upload(changeset(), params(), permitted(), module(), atom()) :: changeset()

Processes an upload for each permitted field found in params, calling the given function to produce a Capsule.Locator and casting it onto the changeset.

The handler function receives {field, value} and the current changeset, and must return either a Capsule.Locator or an Ecto.Changeset (to add errors).

Options

  • :required - when true, adds a validation error for any permitted field not present in params. Defaults to false.

Examples

%MySchema{}
|> Ecto.Changeset.change()
|> Capsule.Ecto.upload(params, [:avatar], fn {_field, upload}, _changeset ->
  Capsule.store(upload, MyStorage)
end)

%MySchema{}
|> Ecto.Changeset.change()
|> Capsule.Ecto.upload(params, [:avatar], MyUploader, :upload, required: true)
Link to this function

upload(changeset, params, permitted, mod, func_name, opts)

View Source

Specs

upload(changeset(), params(), permitted(), module(), atom(), opts()) ::
  changeset()