From 103af66788952a9af1cb61a52c31cf06d14612e2 Mon Sep 17 00:00:00 2001 From: Malte Rohde Date: Wed, 20 Dec 2023 12:07:18 +0100 Subject: [PATCH] remove auto_cast_and_apply_action --- CHANGELOG.md | 1 - lib/bitcrowd_ecto/changeset.ex | 58 ---------------------------------- 2 files changed, 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db1c939..82e554b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,6 @@ ### Added * Add `BitcrowdEcto.Changeset.auto_cast/3`, a introspection-based automatic cast function. -* Add `BitcrowdEcto.Changeset.auto_cast_and_apply_action/3`, a convenient wrapper around `auto_cast/3` that directly returns a schema struct. * Add `BitcrowdEcto.Assertions.assert_cast_error_on/2`. ### Fixed diff --git a/lib/bitcrowd_ecto/changeset.ex b/lib/bitcrowd_ecto/changeset.ex index 15e5f7c..4ad3584 100644 --- a/lib/bitcrowd_ecto/changeset.ex +++ b/lib/bitcrowd_ecto/changeset.ex @@ -539,62 +539,4 @@ defmodule BitcrowdEcto.Changeset do Ecto.Changeset.cast_embed(cs, embed, required: embed in required) end) end - - @type action_option :: {:action, :insert | :update} - - @doc """ - Convenience function calling `auto_cast/3` and `apply_action/2` in one step. - - ## Options - - - `action` the action to apply to the changeset (`:insert` or `:update`, defaults to `:insert`) - - all options from `auto_cast/3` - - ## Example - - iex> auto_cast_and_apply(TestEmbeddedSchema, %{some_field: 4}) - {:ok, %TestEmbeddedSchema{some_field: 4}} - """ - @doc since: "0.17.0" - @spec auto_cast_and_apply(module | struct, map) :: - {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()} - @spec auto_cast_and_apply(module | struct, map, [auto_cast_option | action_option]) :: - {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()} - def auto_cast_and_apply(schema_or_struct_or_changeset, params, opts \\ []) do - do_auto_cast_and_apply( - schema_or_struct_or_changeset, - params, - &Ecto.Changeset.apply_action/2, - opts - ) - end - - @doc """ - Explosive variant of `auto_cast_and_apply/3`. - - ## Example - - iex> auto_cast_and_apply!(TestEmbeddedSchema, %{some_field: 4}) - %TestEmbeddedSchema{some_field: 4} - """ - @doc since: "0.17.0" - @spec auto_cast_and_apply!(module | struct, map) :: Ecto.Schema.t() | no_return - @spec auto_cast_and_apply!(module | struct, map, [auto_cast_option | action_option]) :: - Ecto.Schema.t() | no_return - def auto_cast_and_apply!(schema_or_struct_or_changeset, params, opts \\ []) do - do_auto_cast_and_apply( - schema_or_struct_or_changeset, - params, - &Ecto.Changeset.apply_action!/2, - opts - ) - end - - defp do_auto_cast_and_apply(schema_or_struct_or_changeset, params, apply_action, opts) do - {action, opts} = Keyword.pop(opts, :action, :insert) - - schema_or_struct_or_changeset - |> auto_cast(params, opts) - |> apply_action.(action) - end end