Skip to content

Commit

Permalink
refactor builder
Browse files Browse the repository at this point in the history
  • Loading branch information
woylie committed Aug 9, 2021
1 parent d490d5e commit 862c996
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
17 changes: 3 additions & 14 deletions lib/flop/builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Flop.Builder do
@moduledoc false

import Ecto.Query
import Flop.Misc

alias Flop.Filter
alias Flop.Misc
Expand Down Expand Up @@ -151,13 +152,7 @@ defmodule Flop.Builder do
# prevent unused variable warning for operators that don't use value
_ = value

unquote(
if dynamic_builder do
dynamic_builder
|> String.replace("<<<binding>>>", "[r]")
|> Code.string_to_quoted!()
end
)
unquote(quote_dynamic(dynamic_builder, "[r]"))

unquote(
quote do
Expand All @@ -175,13 +170,7 @@ defmodule Flop.Builder do
# prevent unused variable warning for operators that don't use value
_ = value

unquote(
if dynamic_builder do
dynamic_builder
|> String.replace("<<<binding>>>", "[{^binding, r}]")
|> Code.string_to_quoted!()
end
)
unquote(quote_dynamic(dynamic_builder, "[{^binding, r}]"))

unquote(
quote do
Expand Down
9 changes: 9 additions & 0 deletions lib/flop/misc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ defmodule Flop.Misc do
def add_wildcard(value), do: "%#{value}%"

def split_search_text(s), do: s |> String.split() |> Enum.map(&add_wildcard/1)

def quote_dynamic(nil, _), do: nil

def quote_dynamic(dynamic_builder, binding)
when is_binary(dynamic_builder) do
dynamic_builder
|> String.replace("<<<binding>>>", binding)
|> Code.string_to_quoted!()
end
end

0 comments on commit 862c996

Please sign in to comment.