Skip to content

Commit d89e053

Browse files
Fix some issues
1 parent 3c8584d commit d89e053

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/data_mapper.ex

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ defmodule DataMapper do
6565

6666
# Applies a function to a field.
6767
{from_key, {to_key, fun}}, acc when is_function(fun) ->
68-
Map.put(acc, to_key, fun.(input[from_key]))
68+
case input[from_key] do
69+
nil -> acc
70+
data -> Map.put(acc, to_key, fun.(data))
71+
end
6972

7073
# Nested mapping.
7174
{from_key, {to_key, sub_mapping}}, acc when is_map(sub_mapping) ->
@@ -77,6 +80,7 @@ defmodule DataMapper do
7780

7881
case input[from_key] do
7982
data when is_list(data) -> Enum.map(data, &map(&1, sub_mapping, opts))
83+
nil -> acc
8084
data -> map(data, sub_mapping, opts)
8185
end
8286

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule DataMapper.MixProject do
44
def project do
55
[
66
app: :data_mapper,
7-
version: "0.2.0",
7+
version: "0.2.1",
88
elixir: "~> 1.9",
99
start_permanent: Mix.env() == :prod,
1010
deps: deps(),

0 commit comments

Comments
 (0)