Skip to content

Commit

Permalink
Fix warning caused by usage of deprecated Application.get_env
Browse files Browse the repository at this point in the history
It seems that this should already be fixed, but I think the `function_exported?` check doesn't work for macros.
The minimum version is already Elixir 1.10, so it should be safe to remove the whole check.
  • Loading branch information
LouisMT committed May 16, 2023
1 parent 708a688 commit ac6fd1d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 27 deletions.
12 changes: 1 addition & 11 deletions lib/crontab/cron_expression/ecto_type.ex
@@ -1,14 +1,4 @@
# TODO: Replace with simple Code.ensure_compiled as soon as Elixir minimum
# version is raised to 1.10.

Code
|> function_exported?(:ensure_compiled, 1)
|> if do
match?({:module, Ecto.Type}, Code.ensure_compiled(Ecto.Type))
else
:erlang.apply(Code, :ensure_compiled?, [Ecto.Type])
end
|> if do
if match?({:module, Ecto.Type}, Code.ensure_compiled(Ecto.Type)) do
defmodule Crontab.CronExpression.Ecto.Type do
@moduledoc """
Provides a type for Ecto usage.
Expand Down
8 changes: 1 addition & 7 deletions lib/crontab/scheduler.ex
Expand Up @@ -13,13 +13,7 @@ defmodule Crontab.Scheduler do
@type direction :: :increment | :decrement
@type result :: maybe(NaiveDateTime.t(), any)

# TODO: Remove if when requiring Elixir 1.10 + only
if function_exported?(Application, :compile_env, 3) do
@max_runs Application.compile_env(:crontab, :max_runs, 10_000)
else
# credo:disable-for-next-line Credo.Check.Warning.ApplicationConfigInModuleAttribute
@max_runs Application.get_env(:crontab, :max_runs, 10_000)
end
@max_runs Application.compile_env(:crontab, :max_runs, 10_000)

@doc """
This function provides the functionality to retrieve the next run date from a
Expand Down
10 changes: 1 addition & 9 deletions test/crontab/cron_expression/ecto_type_test.exs
@@ -1,12 +1,4 @@
# TODO: Replace with simple Code.ensure_compiled as soon as Elixir min. version is raised to 1.10
Code
|> function_exported?(:ensure_compiled, 1)
|> if do
match?({:module, Ecto.Type}, Code.ensure_compiled(Ecto.Type))
else
:erlang.apply(Code, :ensure_compiled?, [Ecto.Type])
end
|> if do
if match?({:module, Ecto.Type}, Code.ensure_compiled(Ecto.Type)) do
defmodule Crontab.CronExpression.Ecto.TypeTest do
@moduledoc false

Expand Down

0 comments on commit ac6fd1d

Please sign in to comment.