-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
argument.ex
54 lines (51 loc) · 1.41 KB
/
argument.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
defmodule Ash.Resource.Calculation.Argument do
@moduledoc "An argument to a calculation"
defstruct allow_nil?: true,
allow_expr?: false,
constraints: [],
default: nil,
name: nil,
type: nil
@type t :: %__MODULE__{
allow_nil?: boolean,
allow_expr?: boolean,
constraints: keyword,
default: any,
name: atom,
type: Ash.Type.t()
}
@schema [
name: [
type: :atom,
required: true,
doc: "The name of the argument"
],
type: [
type: Ash.OptionsHelpers.ash_type(),
required: true,
doc: "The type of the argument. See `Ash.Type` for more."
],
default: [
type: {:or, [{:mfa_or_fun, 0}, :literal]},
required: false,
doc: "A default value to use for the argument if not provided"
],
allow_nil?: [
type: :boolean,
default: true,
doc: "Whether or not the argument value may be nil (or may be not provided)"
],
allow_expr?: [
type: :boolean,
default: false,
doc: "Allow passing expressions as argument values. Expressions cannot be type validated."
],
constraints: [
type: :keyword_list,
default: [],
doc:
"Constraints to provide to the type when casting the value. See the type's documentation and `Ash.Type` for more."
]
]
def schema, do: @schema
end