Skip to content

Commit 8706a41

Browse files
committed
Add array modifier
1 parent a56d447 commit 8706a41

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/mix/tasks/gen/ash.gen.resource.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if Code.ensure_loaded?(Igniter) do
2222
2323
## Options
2424
25-
* `--attribute` or `-a` - An attribute or comma separated list of attributes to add, as `name:type`. Modifiers: `primary_key`, `public`, `sensitive`, and `required`. i.e `-a name:string:required`
25+
* `--attribute` or `-a` - An attribute or comma separated list of attributes to add, as `name:type`. Modifiers: `primary_key`, `array`, `public`, `sensitive`, and `required`. i.e `-a name:string:required`
2626
* `--relationship` or `-r` - A relationship or comma separated list of relationships to add, as `type:name:dest`. Modifiers: `public`. `belongs_to` only modifiers: `primary_key`, `sensitive`, and `required`. i.e `-r belongs_to:author:MyApp.Accounts.Author:required`
2727
* `--default-actions` - A csv list of default action types to add. The `create` and `update` actions accept the public attributes being added.
2828
* `--uuid-primary-key` or `-u` - Adds a UUIDv4 primary key with that name. i.e `-u id`
@@ -223,6 +223,9 @@ if Code.ensure_loaded?(Igniter) do
223223
"sensitive" ->
224224
"sensitive? true"
225225

226+
"array" ->
227+
"array"
228+
226229
unknown ->
227230
raise ArgumentError,
228231
"""
@@ -343,7 +346,11 @@ if Code.ensure_loaded?(Igniter) do
343346
end
344347

345348
name_atom = String.to_atom(name)
346-
type = resolve_type(type)
349+
350+
{type, modifiers} =
351+
if Enum.any?(modifiers, &(&1 == "array")),
352+
do: {{:array, resolve_type(type)}, modifiers -- ["array"]},
353+
else: {resolve_type(type), modifiers}
347354

348355
attribute_code =
349356
if Enum.empty?(modifiers) do

0 commit comments

Comments
 (0)