@@ -533,21 +533,32 @@ defmodule Record do
533
533
## Types/specs generation
534
534
535
535
defp core_specs ( values ) do
536
- types = lc { _ , _ , spec } in list values , do: spec
536
+ types = lc { _ , _ , spec } in list values , do: spec
537
+ options = if values == [ ] , do: [ ] , else: [ options_specs ( values ) ]
537
538
538
539
quote do
539
540
unless Kernel.Typespec . defines_type? ( __MODULE__ , :t , 0 ) do
540
541
@ type t :: { __MODULE__ , unquote_splicing ( types ) }
541
542
end
542
543
544
+ unless Kernel.Typespec . defines_type? ( __MODULE__ , :options , 0 ) do
545
+ @ type options :: unquote ( options )
546
+ end
547
+
543
548
@ spec new :: t
544
- @ spec new ( Keyword . t | tuple ) :: t
545
- @ spec to_keywords ( t ) :: Keyword . t
546
- @ spec update ( Keyword . t , t ) :: t
549
+ @ spec new ( options | tuple ) :: t
550
+ @ spec to_keywords ( t ) :: options
551
+ @ spec update ( options , t ) :: t
547
552
@ spec __index__ ( atom ) :: non_neg_integer | nil
548
553
end
549
554
end
550
555
556
+ defp options_specs ( [ { k , _ , v } | t ] ) do
557
+ :lists . foldl fn { k , _ , v } , acc ->
558
+ { :| , [ ] , { k , v } , acc }
559
+ end , { k , v } , t
560
+ end
561
+
551
562
defp accessor_specs ( [ { :__exception__ , _ , _ } | t ] , 1 , acc ) do
552
563
accessor_specs ( t , 2 , acc )
553
564
end
0 commit comments