Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Idiomatic elixir, use credo #54

Merged
merged 3 commits into from
Mar 8, 2017
Merged

Idiomatic elixir, use credo #54

merged 3 commits into from
Mar 8, 2017

Conversation

davydog187
Copy link
Contributor

I've been using canary in a side project of mine, and noticed that the codebase could be cleaned up a bit in terms of idiomatic elixir code.

Made several changes to simplify code, and make it more idiomatic.

As far as credo goes, disabled PipeChainStart and Specs

Copy link
Owner

@cpjk cpjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, great changes.

Thanks for cleaning things up! 😄

Just one small nitpick: if we're going to use yoda assignment in function arguments, it should be consistent throughout the file, e.g. https://github.com/cpjk/canary/pull/54/files#diff-3938ea297feb0d441ffe05cec9da28eaR279

Other than that, LGTM.


defp fetch_resource(conn, opts) do
repo = Application.get_env(:canary, :repo)

field_name = (opts[:id_field] || "id")

get_map_args = %{field_name => get_resource_id(conn, opts)}
get_map_args = (for {key, val} <- get_map_args, into: %{}, do: {String.to_atom(key), val})
get_map_args = %{String.to_atom(field_name) => get_resource_id(conn, opts)}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning this up!

@@ -414,26 +413,31 @@ defmodule Canary.Plugs do
end
end

defp handle_unauthorized(conn = %{skip_canary_handler: true}, _opts),
defp handle_unauthorized(%{skip_canary_handler: true} = conn, _opts),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the yoda syntax, but if we are going to use it here, it should be used throught the whole code base for consistency, e.g. https://github.com/cpjk/canary/pull/54/files#diff-3938ea297feb0d441ffe05cec9da28eaR282

@davydog187
Copy link
Contributor Author

@cpjk Addressed the other yoda cases. Also fixed the merge conflict. Should be good now

@cpjk
Copy link
Owner

cpjk commented Mar 8, 2017

Sorry for the delay! The email got caught up in my work github notifications 😄.

LGTM! 🚀

@cpjk cpjk merged commit 9bfee2a into cpjk:master Mar 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants