Skip to content

Commit bf20497

Browse files
committed
refactor: extract append_schema_entries to Helpers module
1 parent efe6cfa commit bf20497

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

lib/spark/builder/entity.ex

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,7 @@ defmodule Spark.Builder.Entity do
562562
end
563563

564564
defp merge_schema(%__MODULE__{} = builder, entries) do
565-
%{builder | schema: append_schema_entries(builder.schema, entries)}
566-
end
567-
568-
defp append_schema_entries(schema, entries) do
569-
existing_keys = schema |> Keyword.keys() |> MapSet.new()
570-
schema ++ Enum.reject(entries, fn {key, _} -> MapSet.member?(existing_keys, key) end)
565+
%{builder | schema: Helpers.append_schema_entries(builder.schema, entries)}
571566
end
572567

573568
defp resolve_entity(value) do

lib/spark/builder/helpers.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ defmodule Spark.Builder.Helpers do
4343
Enum.map(values, &resolve(&1, build_fun, predicate))
4444
end
4545

46+
@spec append_schema_entries(Spark.Options.schema(), Spark.Options.schema()) ::
47+
Spark.Options.schema()
48+
def append_schema_entries(schema, entries) do
49+
existing_keys = schema |> Keyword.keys() |> MapSet.new()
50+
schema ++ Enum.reject(entries, fn {key, _} -> MapSet.member?(existing_keys, key) end)
51+
end
52+
4653
defp run_validations([]), do: :ok
4754

4855
defp run_validations([validation | rest]) when is_function(validation, 0) do

lib/spark/builder/section.ex

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ defmodule Spark.Builder.Section do
116116
"""
117117
@spec option(t(), atom(), keyword()) :: t()
118118
def option(%__MODULE__{} = builder, name, opts \\ []) when is_atom(name) and is_list(opts) do
119-
%{builder | schema: append_schema_entries(builder.schema, [{name, opts}])}
119+
%{builder | schema: Helpers.append_schema_entries(builder.schema, [{name, opts}])}
120120
end
121121

122122
# ===========================================================================
@@ -455,9 +455,4 @@ defmodule Spark.Builder.Section do
455455
defp resolve_sections(values) do
456456
Helpers.resolve_list(values, &build!/1, &match?(%DslSection{}, &1))
457457
end
458-
459-
defp append_schema_entries(schema, entries) do
460-
existing_keys = schema |> Keyword.keys() |> MapSet.new()
461-
schema ++ Enum.reject(entries, fn {key, _} -> MapSet.member?(existing_keys, key) end)
462-
end
463458
end

0 commit comments

Comments
 (0)