Skip to content

Commit

Permalink
rewrite put_all_env to support elixir < 1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
axelson authored and fhunleth committed Nov 30, 2021
1 parent 37f7696 commit da07ac9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test/support/application_env_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@ defmodule RingLogger.ApplicationEnvHelpers do

for {app, envs} <- application_envs do
original_envs = Application.get_all_env(app)
Application.put_all_env([{app, envs}])
put_all_env([{app, envs}])

on_exit.(fn ->
# We need to delete all the existing env because `Application.put_all_env` does a deep merge
for {key, _val} <- Application.get_all_env(app), do: Application.delete_env(app, key)
Application.put_all_env([{app, original_envs}])
put_all_env([{app, original_envs}])
end)
end
end

def with_application_env(_context, _on_exit), do: :ok

# `Application.put_all_env/2` is not availble until Elixir 1.9
defp put_all_env(application_envs) do
for {app, envs} <- application_envs,
{key, val} <- envs do
Application.put_env(app, key, val)
end
end
end

0 comments on commit da07ac9

Please sign in to comment.