Skip to content

Commit 026930d

Browse files
committed
make option names more explicit
1 parent 886396f commit 026930d

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Unreleased
44

5+
## [0.1.1] - 2021-08-28
6+
7+
### Changed
8+
9+
- Rename `mode` options `:replace` and `:delete` to `{:action, :replace}` and
10+
`{:action, :delete}`.
11+
512
## [0.1.0] - 2021-08-28
613

714
initial release

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Add `ecto_nested_changeset` to your list of dependencies in `mix.exs`:
1111
```elixir
1212
def deps do
1313
[
14-
{:ecto_nested_changeset, "~> 0.1.0"}
14+
{:ecto_nested_changeset, "~> 0.1.1"}
1515
]
1616
end
1717
```
@@ -39,7 +39,7 @@ category
3939
|> Ecto.Changeset.change()
4040
|> append_at(:posts, %Post{title: "Padawan", comments: []})
4141
|> prepend_at([:posts, 0, :comments], %Comment{body: "ecneitaP"})
42-
|> delete_at([:posts, 0, :comments, 1], mode: :delete)
42+
|> delete_at([:posts, 0, :comments, 1], mode: {:action, :delete})
4343
|> insert_at([:posts, 1], %Post{title: "have"})
4444
|> append_at([:posts, 2, :comments], %Comment{body: "my"})
4545
|> update_at([:posts, 0, :comments, 0, :body], &String.reverse/1)

lib/ecto_nested_changeset.ex

+9-9
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ defmodule EctoNestedChangeset do
141141
the list. For structs that are already persisted in the database, there are
142142
three different modes.
143143
144-
- `[mode: :replace]` (default) - The item will be wrapped in a changeset with
145-
the `:replace` action. This only works if an appropriate `:on_replace`
146-
option is set for the relation in the schema.
147-
- `[mode: :delete]` - The item will be wrapped in a changeset with the action
148-
set to `:delete`.
144+
- `[mode: {:action, :replace}]` (default) - The item will be wrapped in a
145+
changeset with the `:replace` action. This only works if an appropriate
146+
`:on_replace` option is set for the relation in the schema.
147+
- `[mode: {:action, :delete}]` - The item will be wrapped in a changeset with
148+
the action set to `:delete`.
149149
- `[mode: {:flag, field}]` - Puts `true` as a change for the given field.
150150
151151
The flag option useful for explicitly marking items for deletion in form
@@ -183,7 +183,7 @@ defmodule EctoNestedChangeset do
183183
%Changeset{action: :update, data: %Post{name: "George"}},
184184
]
185185
}
186-
iex> delete_at(changeset, [:pets, 1], mode: :delete)
186+
iex> delete_at(changeset, [:pets, 1], mode: {:action, :delete})
187187
%Ecto.Changeset{
188188
changes: [
189189
%Changeset{action: :update, data: %Post{name: "George"}},
@@ -271,15 +271,15 @@ defmodule EctoNestedChangeset do
271271
List.delete_at(items, index)
272272

273273
%{} = item ->
274-
case opts[:mode] || :replace do
275-
:delete ->
274+
case opts[:mode] || {:action, :replace} do
275+
{:action, :delete} ->
276276
List.replace_at(
277277
items,
278278
index,
279279
item |> change() |> Map.put(:action, :delete)
280280
)
281281

282-
:replace ->
282+
{:action, :replace} ->
283283
List.delete_at(items, index)
284284

285285
{:flag, field} ->

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule EctoNestedChangeset.MixProject do
22
use Mix.Project
33

4-
@version "0.1.0"
4+
@version "0.1.1"
55
@source_url "https://github.com/woylie/ecto_nested_changeset"
66

77
def project do

test/ecto_nested_changeset_test.exs

+6-6
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ defmodule EctoNestedChangesetTest do
574574
}
575575
|> change()
576576
|> prepend_at([:posts], %Post{})
577-
|> delete_at([:posts, 2], mode: :delete)
578-
|> delete_at([:posts, 0], mode: :delete)
577+
|> delete_at([:posts, 2], mode: {:action, :delete})
578+
|> delete_at([:posts, 0], mode: {:action, :delete})
579579

580580
assert %{
581581
posts: [
@@ -598,8 +598,8 @@ defmodule EctoNestedChangesetTest do
598598
}
599599
|> change()
600600
|> prepend_at([:posts], %Post{})
601-
|> delete_at([:posts, 0], mode: :replace)
602-
|> delete_at([:posts, 1], mode: :replace)
601+
|> delete_at([:posts, 0], mode: {:action, :replace})
602+
|> delete_at([:posts, 1], mode: {:action, :replace})
603603

604604
assert %{
605605
posts: [
@@ -677,8 +677,8 @@ defmodule EctoNestedChangesetTest do
677677
]
678678
}
679679
|> change()
680-
|> delete_at([:posts, 1, :comments, 0], mode: :delete)
681-
|> delete_at([:posts, 0, :comments, 1], mode: :delete)
680+
|> delete_at([:posts, 1, :comments, 0], mode: {:action, :delete})
681+
|> delete_at([:posts, 0, :comments, 1], mode: {:action, :delete})
682682

683683
assert %{
684684
posts: [

0 commit comments

Comments
 (0)