-
Notifications
You must be signed in to change notification settings - Fork 19
Added keys_to_atoms option for display maps #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
38c3435
453c1a3
018c281
8a70f91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,13 +116,30 @@ defimpl Apex.Format, for: Map do | |
end | ||
|
||
def format(data, options) do | ||
Apex.Format.Seq.format( | ||
Map.to_list(data), | ||
options, | ||
start_token: "\%{", | ||
end_token: "}", | ||
numbers: false) |> colorize(data, options) | ||
end | ||
ap_options = :apex | ||
|> Application.get_all_env | ||
|> Keyword.merge(options) | ||
|
||
data | ||
|> keys_to_atoms(ap_options[:keys_to_atoms]) | ||
|> Map.to_list | ||
|> Apex.Format.Seq.format( | ||
ap_options, | ||
start_token: "\%{", | ||
end_token: "}", | ||
numbers: false) | ||
|> colorize(data, ap_options) | ||
end | ||
|
||
defp keys_to_atoms(data, shouldConvert) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also only a small nitpick. Please use "snake_case" for parameter names, so |
||
defp keys_to_atoms(data, true) do | ||
Map.new(data, fn {k,v} -> { convert_to_atom(k), v} end) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's inconsistent whitespace usage here before
Please remove the whitespace for the sake of consistency |
||
end | ||
defp keys_to_atoms(data, _), do: data | ||
|
||
defp convert_to_atom(key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
defp convert_to_atom(key) when is_binary(key), do: String.to_atom(key) | ||
defp convert_to_atom(key), do: key | ||
end | ||
|
||
defimpl Apex.Format, for: Any do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably not do the config reading here. Doing it here would only apply it for the
Map
protocol implementation.A better position would be in
ap
before the protocol invocation here.Then I would also probably extract it into
defp configuration(options)
.