File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ defmodule AtomicMap do
1919 def convert ( list , opts ) when is_list ( list ) do
2020 list |> Enum . map ( fn ( x ) -> convert ( x , opts ) end )
2121 end
22+ def convert ( tuple , opts ) when is_tuple ( tuple ) do
23+ tuple |> Tuple . to_list |> convert ( opts ) |> List . to_tuple
24+ end
2225 def convert ( v , _opts ) , do: v
2326 defp as_atom ( s , true ) when is_binary ( s ) , do: s |> String . to_existing_atom
2427 defp as_atom ( s , true ) , do: s
Original file line number Diff line number Diff line change @@ -54,6 +54,12 @@ defmodule AtomicMapTest do
5454 assert AtomicMap . convert ( input ) == expected
5555 end
5656
57+ test "works with tuples" do
58+ input = % { "first" => { 1 , 2 } }
59+ expected = % { first: { 1 , 2 } }
60+ assert AtomicMap . convert ( input ) == expected
61+ end
62+
5763 test "raises for not existing atoms" do
5864 assert_raise ArgumentError , fn ->
5965 input = % { "a" => 2 , "b" => % { "c" => 4 } , "__not___existing__" => 5 }
You can’t perform that action at this time.
0 commit comments