Skip to content

Commit

Permalink
Make Formulae dep optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Matiushkin committed Mar 1, 2024
1 parent a3c8981 commit 67eaa7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/estructura.ex
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ defmodule Estructura do
fn {field, formula}, acc ->
value =
case formula do
%Formulae{} = f ->
Formulae.eval(f, acc |> Map.from_struct() |> Map.to_list())
%{__struct__: Formulae} = f ->
# credo:disable-for-next-line
apply(Formulae, :eval, [f, acc |> Map.from_struct() |> Map.to_list()])

f when is_function(f, 1) ->
f.(acc)
Expand Down
11 changes: 9 additions & 2 deletions lib/estructura/hooks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ defmodule Estructura.Hooks do
:calculated,
unquote(calculated)
|> Enum.map(fn
{k, %Formulae{} = formula} ->
{k, %{__struct__: Formulae} = formula} ->
{k, formula}

{k, formula} when is_binary(formula) ->
{k, Formulae.compile(formula, imports: :none)}
{
k,
# credo:disable-for-next-line
apply(Formulae, :compile, [
formula,
[imports: :none]
])
}

{k, formula} when is_function(formula, 1) ->
{k, formula}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ defmodule Estructura.MixProject do

defp deps do
[
{:formulae, "~> 0.14"},
{:stream_data, "~> 0.5"},
{:formulae, "~> 0.14", optional: true},
{:jason, "~> 1.0", optional: true},
{:excoveralls, "~> 0.14", only: [:test, :ci], runtime: false},
{:credo, "~> 1.0", only: [:dev, :test, :ci]},
Expand Down

0 comments on commit 67eaa7e

Please sign in to comment.