Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zimt28
Copy link

@zimt28 zimt28 commented Dec 16, 2023

Closes #11

@zimt28 zimt28 changed the title feat: add support for custom function names (#11) feat: add support for custom function names #11 Dec 16, 2023
@zimt28 zimt28 changed the title feat: add support for custom function names #11 feat: add support for custom function names Dec 16, 2023
Copy link
Owner

@emadalam emadalam left a 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.
Copy link
Owner

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()
Copy link
Owner

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Add fun option
2 participants