@@ -12,12 +12,14 @@ defmodule Construct.Hooks.Fasten do
1212 def __compile__ ( module , fields ) do
1313 cast_defs =
1414 Enum . map ( fields , fn ( { name , type , opts } ) ->
15+ function_name = :"__cast_#{ name } __"
16+
1517 { default_before_clause , default_after_clause } =
1618 case Keyword . get ( opts , :default ) do
1719 :__construct_no_default_value__ ->
1820 clause_after =
1921 quote do
20- def unquote ( :"cast_ #{ name } " ) ( _ , _ ) do
22+ defp unquote ( function_name ) ( _ , _ ) do
2123 { :error , % { unquote ( name ) => :missing } }
2224 end
2325 end
@@ -27,7 +29,7 @@ defmodule Construct.Hooks.Fasten do
2729 nil ->
2830 clause_after =
2931 quote do
30- def unquote ( :"cast_ #{ name } " ) ( _ , _ ) do
32+ defp unquote ( function_name ) ( _ , _ ) do
3133 { :error , % { unquote ( name ) => :missing } }
3234 end
3335 end
@@ -39,18 +41,18 @@ defmodule Construct.Hooks.Fasten do
3941
4042 clause_before =
4143 quote do
42- def unquote ( :"cast_ #{ name } " ) ( % { unquote ( to_string ( name ) ) => term } , _opts ) when term == unquote ( term ) do
44+ defp unquote ( function_name ) ( % { unquote ( to_string ( name ) ) => term } , _opts ) when term == unquote ( term ) do
4345 { :ok , unquote ( term ) }
4446 end
4547
46- def unquote ( :"cast_ #{ name } " ) ( % { unquote ( name ) => term } , _opts ) when term == unquote ( term ) do
48+ defp unquote ( function_name ) ( % { unquote ( name ) => term } , _opts ) when term == unquote ( term ) do
4749 { :ok , unquote ( term ) }
4850 end
4951 end
5052
5153 clause_after =
5254 quote do
53- def unquote ( :"cast_ #{ name } " ) ( _ , _ ) do
55+ defp unquote ( function_name ) ( _ , _ ) do
5456 { :ok , unquote ( term ) }
5557 end
5658 end
@@ -60,11 +62,11 @@ defmodule Construct.Hooks.Fasten do
6062
6163 cast_clause =
6264 quote do
63- def unquote ( :"cast_ #{ name } " ) ( % { unquote ( to_string ( name ) ) => term } , opts ) do
65+ defp unquote ( function_name ) ( % { unquote ( to_string ( name ) ) => term } , opts ) do
6466 Construct.Type . cast ( unquote ( type ) , term , opts )
6567 end
6668
67- def unquote ( :"cast_ #{ name } " ) ( % { unquote ( name ) => term } , opts ) do
69+ defp unquote ( function_name ) ( % { unquote ( name ) => term } , opts ) do
6870 Construct.Type . cast ( unquote ( type ) , term , opts )
6971 end
7072 end
@@ -90,7 +92,7 @@ defmodule Construct.Hooks.Fasten do
9092 with_matches =
9193 Enum . map ( fields , fn ( { name , _type , _opts } ) ->
9294 quote do
93- { :ok , unquote ( Macro . var ( name , nil ) ) } <- unquote ( :"cast_ #{ name } " ) ( params , opts )
95+ { :ok , unquote ( Macro . var ( name , nil ) ) } <- unquote ( :"__cast_ #{ name } __ " ) ( params , opts )
9496 end
9597 end )
9698
@@ -104,7 +106,6 @@ defmodule Construct.Hooks.Fasten do
104106 end
105107
106108 merge_blocks ( make_ast , cast_defs )
107- |> tap ( fn ( ast ) -> IO . puts ( Macro . to_string ( ast ) ) end )
108109 end
109110
110111 defp merge_blocks ( a , b ) do
0 commit comments