-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: add support for custom function names #12
base: main
Are you sure you want to change the base?
Conversation
270c7d8
to
8ea53ca
Compare
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.
Thank you for this PR. It looks good, just minor nitpicks and we are good to go ✌️
One suggestion. Could you maybe create a PR against the dev
branch that I had created? This way we can add more features before a release to hex package manager.
@@ -217,6 +217,23 @@ defmodule MyApp.Env do | |||
end | |||
``` | |||
|
|||
## Setting custom function names | |||
|
|||
You can use the `fun` option to use a custom function name instead of the default one. |
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.
How about adding a more descriptive information in the docs.
"By default the lowercase string version of the environment variable names are used to generate the corresponding function names. However you can override this behaviour by using the fun
option to use a custom function name instead of the default one."
@@ -20,7 +20,12 @@ defmodule Mahaul do | |||
|
|||
Enum.each(opts, fn {key, val} -> | |||
str_key = Atom.to_string(key) | |||
fn_name = str_key |> String.downcase() |> String.to_atom() | |||
fn_name_default = str_key |> String.downcase() |> String.to_atom() |
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.
You can move this statement down in the else block to keep the function name generation inside a single block and avoid computation in unused case.
fn_name =
if Keyword.keyword?(val) && Keyword.get(val, :fun, "") |> is_atom(),
do: Keyword.get(val, :fun),
else: str_key |> String.downcase() |> String.to_atom()
Closes #11