Created
August 28, 2019 07:04
-
-
Save x4lldux/88f1e9f5930a0b38dfbfaa17d7cfacaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule PropCheckConfig do | |
def config() do | |
[:quiet] | |
|> push("NUMTESTS", "30", :numtests, &opt_num_value/2) | |
|> maybe_push("VERBOSE", :verbose) | |
|> maybe_push("MAX_SIZE", :max_size, &opt_num_value/2) | |
end | |
defp opt_num_value(name, val), do: {name, String.to_integer(val)} | |
defp push(cfg, env_var, default , opt_name, transform \\ fn opt, _val -> opt end) do | |
case System.get_env(env_var) do | |
nil -> [transform.(opt_name, default) | cfg] | |
val -> [transform.(opt_name, val) | cfg] | |
end | |
end | |
defp maybe_push(cfg, env_var, opt_name, transform \\ fn opt, _val -> opt end) do | |
case System.get_env(env_var) do | |
nil -> cfg | |
val -> [transform.(opt_name, val) | cfg] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment