Skip to content

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwinchester committed Aug 19, 2024
1 parent 3c8584d commit d89e053
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/data_mapper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ defmodule DataMapper do

# Applies a function to a field.
{from_key, {to_key, fun}}, acc when is_function(fun) ->
Map.put(acc, to_key, fun.(input[from_key]))
case input[from_key] do
nil -> acc
data -> Map.put(acc, to_key, fun.(data))
end

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

case input[from_key] do
data when is_list(data) -> Enum.map(data, &map(&1, sub_mapping, opts))
nil -> acc
data -> map(data, sub_mapping, opts)
end

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule DataMapper.MixProject do
def project do
[
app: :data_mapper,
version: "0.2.0",
version: "0.2.1",
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down

0 comments on commit d89e053

Please sign in to comment.