Skip to content

Commit 25c3c82

Browse files
authored
Merge pull request #66 from gmile/remove-dicts
Clean up Dict usage
2 parents d6fce7a + 22f450b commit 25c3c82

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

lib/exvcr/task/runner.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ defmodule ExVCR.Task.Runner do
9090
defp create_count_hash([], acc), do: acc
9191
defp create_count_hash([{type, path}|tail], acc) do
9292
file = Path.basename(path)
93-
counts = Dict.get(acc, file, %ExVCR.Checker.Counts{})
93+
counts = Map.get(acc, file, %ExVCR.Checker.Counts{})
9494
hash = case type do
95-
:cache -> Dict.put(acc, file, %{counts | cache: counts.cache + 1})
96-
:server -> Dict.put(acc, file, %{counts | server: counts.server + 1})
95+
:cache -> Map.put(acc, file, %{counts | cache: counts.cache + 1})
96+
:server -> Map.put(acc, file, %{counts | server: counts.server + 1})
9797
end
9898
create_count_hash(tail, hash)
9999
end
100100

101101
defp print_check_cassettes(items, counts_hash) do
102102
printf(@check_header_format, ["[File Name]", "[Cassette Counts]", "[Server Counts]"])
103103
Enum.each(items, fn({name, _date}) ->
104-
counts = Dict.get(counts_hash, name, %ExVCR.Checker.Counts{})
104+
counts = Map.get(counts_hash, name, %ExVCR.Checker.Counts{})
105105
printf(@check_content_format, [name, counts.cache, counts.server])
106106
end)
107107
end

lib/exvcr/task/show.ex

+5-12
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,10 @@ defmodule ExVCR.Task.Show do
3434
end
3535

3636
defp extract_body(json) do
37-
response = JSX.decode!(json)
38-
|> List.first
39-
|> Enum.into(HashDict.new)
40-
|> fetch_value("response")
41-
Enum.into(response, HashDict.new) |> fetch_value("body")
42-
end
43-
44-
defp fetch_value(dict, key) do
45-
case HashDict.fetch(dict, key) do
46-
{:ok, value} -> value
47-
_ -> []
48-
end
37+
json
38+
|> JSX.decode!()
39+
|> List.first()
40+
|> Enum.into(%{})
41+
|> get_in(["responce", "body"])
4942
end
5043
end

0 commit comments

Comments
 (0)