Skip to content

Commit

Permalink
Assigns indifferent access
Browse files Browse the repository at this point in the history
  • Loading branch information
barkerja committed Apr 30, 2024
1 parent 88bc449 commit 97285a6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/solid/matcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defimpl Solid.Matcher, for: Map do
end

def match(data, [key | []]) do
case Map.fetch(data, key) do
case get_data(data, key) do
{:ok, value} when is_function(value, 1) ->
case value.(data) do
{:ok, value} -> {:ok, value}
Expand All @@ -51,7 +51,7 @@ defimpl Solid.Matcher, for: Map do
end

def match(data, [key | keys]) do
case Map.fetch(data, key) do
case get_data(data, key) do
{:ok, value} when is_function(value, 1) ->
case value.(data) do
{:ok, value} ->
Expand All @@ -68,6 +68,19 @@ defimpl Solid.Matcher, for: Map do
{:error, :not_found}
end
end

defp get_data(data, key) do
string_key = if is_atom(key), do: Atom.to_string(key), else: key
atom_key = if is_bitstring(key), do: String.to_atom(key), else: key

case Map.fetch(data, atom_key) do
:error ->
Map.fetch(data, string_key)

{:ok, data} ->
{:ok, data}
end
end
end

defimpl Solid.Matcher, for: BitString do
Expand Down

0 comments on commit 97285a6

Please sign in to comment.