Skip to content

Commit 74ccb69

Browse files
committed
removed Encoder implementation for maps and changed the assign_ids function to reflect the Encoder implementation.
1 parent 8d97973 commit 74ccb69

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/mongo/encoder.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,3 @@ defprotocol Mongo.Encoder do
44
@spec encode(t) :: map()
55
def encode(value)
66
end
7-
8-
defimpl Mongo.Encoder, for: Map do
9-
def encode(v), do: v
10-
end

lib/utils.ex

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ defmodule Mongo.Utils do
22

33
def assign_ids(list) when is_list(list) do
44
list
5-
|> Enum.map(&Mongo.Encoder.encode/1)
6-
|> Enum.map(&assign_id/1)
5+
|> Enum.map(fn item ->
6+
case Mongo.Encoder.impl_for(item) do
7+
nil ->
8+
item
9+
10+
_ ->
11+
Mongo.Encoder.encode(item)
12+
end
13+
end)
14+
|> Enum.map(fn item -> assign_id(item) end)
715
|> Enum.unzip()
816
end
917

@@ -17,7 +25,9 @@ defmodule Mongo.Utils do
1725
end
1826

1927
defp assign_id(map) when is_map(map) do
20-
map |> Map.to_list() |> add_id()
28+
map
29+
|> Map.to_list()
30+
|> add_id()
2131
end
2232

2333
##

0 commit comments

Comments
 (0)