Skip to content

Commit

Permalink
struct with overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Ecialo committed Nov 19, 2020
1 parent b349877 commit 6bf05be
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/thrift/generator/test_data_generator/struct.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,32 @@ defmodule Thrift.Generator.TestDataGenerator.Struct do
quote do
defmodule unquote(test_data_module_name) do
use PropCheck
alias Thrift.Generator.TestDataGenerator

def get_generator(context \\ nil, props \\ []) do
def get_generator(context \\ [], props \\ []) do
ctx = Enum.map(context, &handler_module_from_context/1)

f =
TestDataGenerator.find_first_realization(
ctx,
{:get_generator, 2},
&get_default_generator/2
)

f.(context, props)
end

def get_default_generator(context \\ nil, props \\ []) do
unquote(gen)
end

def apply_defaults(struct_, context \\ nil) do
unquote(gen_replace)
end

defp handler_module_from_context(context) do
Module.concat(context, unquote(name))
end
end
end
end
Expand Down Expand Up @@ -131,4 +149,5 @@ defmodule Thrift.Generator.TestDataGenerator.Struct do
end
end
end

end

0 comments on commit 6bf05be

Please sign in to comment.