File tree Expand file tree Collapse file tree 4 files changed +23
-2
lines changed
Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 11## Changelog
22
3+ ## v2.1.10
4+
5+ * Enhancements
6+ * Add ` enforce_keys ` option to not enforce keys when building struct
7+
38## v2.1.9
49
510* Enhancements
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ defmodule Construct do
5858
5959 quote do
6060 @ behaviour Construct
61+ @ construct_opts unquote ( opts )
6162
6263 unquote ( pre_ast )
6364
@@ -275,7 +276,12 @@ defmodule Construct do
275276 |> Enum . reverse ( )
276277
277278 quote do
278- @ enforce_keys unquote ( enforce_fields )
279+ enforce_keys = Keyword . get ( @ construct_opts , :enforce_keys , true )
280+
281+ if enforce_keys do
282+ @ enforce_keys unquote ( enforce_fields )
283+ end
284+
279285 defstruct unquote ( Macro . escape ( fields ) )
280286 end
281287 end
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ defmodule Construct.Mixfile do
44 def project do
55 [
66 app: :construct ,
7- version: "2.1.9 " ,
7+ version: "2.1.10 " ,
88 elixir: "~> 1.5" ,
99 deps: deps ( ) ,
1010 elixirc_paths: elixirc_paths ( Mix . env ) ,
Original file line number Diff line number Diff line change @@ -53,6 +53,14 @@ defmodule Construct.Integration.StructTest do
5353 end
5454 end
5555
56+ defmodule Test5 do
57+ use Construct , enforce_keys: false
58+
59+ structure do
60+ field :a , :string
61+ end
62+ end
63+
5664 test "struct should be equal with make" do
5765 assert struct! ( Test0 ) == Test0 . make! ( )
5866 end
@@ -96,6 +104,8 @@ defmodule Construct.Integration.StructTest do
96104 end )
97105
98106 assert { :ok , % Test4 { a: % Time { } } } = Test4 . make ( )
107+
108+ assert % Test5 { a: nil } = struct! ( Test5 )
99109 end
100110
101111 test "cycle deps" do
You can’t perform that action at this time.
0 commit comments