Skip to content

Commit b83d6ac

Browse files
authored
chore(docs): Update custom_input with and transform examples to return value only (#1938)
1 parent f406c62 commit b83d6ac

File tree

4 files changed

+42
-43
lines changed

4 files changed

+42
-43
lines changed

documentation/dsls/DSL-Ash.Domain.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ custom_input name, type
147147
```
148148

149149

150-
Define or customize an input to the action.
150+
Define or customize an input to the action.
151151

152152
See the [code interface guide](/documentation/topics/resources/code-interfaces.md) for more.
153153

@@ -159,7 +159,7 @@ See the [code interface guide](/documentation/topics/resources/code-interfaces.m
159159
### Examples
160160
```
161161
custom_input :artist, :struct do
162-
transform to: :artist_id, with: &{:ok, &1.id}
162+
transform to: :artist_id, using: &(&1.id)
163163
164164
constraints instance_of: Artist
165165
end
@@ -195,17 +195,17 @@ A transformation to be applied to the custom input.
195195

196196
### Examples
197197
```
198-
transform do
198+
transform do
199199
to :artist_id
200-
with &{:ok, &1.id}
200+
using &(&1.id)
201201
end
202202
203203
```
204204

205205
```
206-
transform do
206+
transform do
207207
to :points
208-
with &try_parse_integer/1
208+
using &try_parse_integer/1
209209
end
210210
211211
```
@@ -218,7 +218,7 @@ end
218218
| Name | Type | Default | Docs |
219219
|------|------|---------|------|
220220
| [`to`](#resources-resource-define-custom_input-transform-to){: #resources-resource-define-custom_input-transform-to } | `atom` | | A key to rewrite the argument to. If the custom input is also a required positional argument, then the `to` is automatically added to the `exclude_inputs` list. |
221-
| [`using`](#resources-resource-define-custom_input-transform-using){: #resources-resource-define-custom_input-transform-using } | `(any -> any)` | | A function to use to transform the value. Must return `{:ok, value}` or `{:error, error}` |
221+
| [`using`](#resources-resource-define-custom_input-transform-using){: #resources-resource-define-custom_input-transform-using } | `(any -> any)` | | A function to use to transform the value. Must return `value` or `nil` |
222222

223223

224224

@@ -287,7 +287,7 @@ custom_input name, type
287287
```
288288

289289

290-
Define or customize an input to the action.
290+
Define or customize an input to the action.
291291

292292
See the [code interface guide](/documentation/topics/resources/code-interfaces.md) for more.
293293

@@ -299,7 +299,7 @@ See the [code interface guide](/documentation/topics/resources/code-interfaces.m
299299
### Examples
300300
```
301301
custom_input :artist, :struct do
302-
transform to: :artist_id, with: &{:ok, &1.id}
302+
transform to: :artist_id, using: &(&1.id)
303303
304304
constraints instance_of: Artist
305305
end
@@ -335,17 +335,17 @@ A transformation to be applied to the custom input.
335335

336336
### Examples
337337
```
338-
transform do
338+
transform do
339339
to :artist_id
340-
with &{:ok, &1.id}
340+
using &(&1.id)
341341
end
342342
343343
```
344344

345345
```
346-
transform do
346+
transform do
347347
to :points
348-
with &try_parse_integer/1
348+
using &try_parse_integer/1
349349
end
350350
351351
```
@@ -358,7 +358,7 @@ end
358358
| Name | Type | Default | Docs |
359359
|------|------|---------|------|
360360
| [`to`](#resources-resource-define_calculation-custom_input-transform-to){: #resources-resource-define_calculation-custom_input-transform-to } | `atom` | | A key to rewrite the argument to. If the custom input is also a required positional argument, then the `to` is automatically added to the `exclude_inputs` list. |
361-
| [`using`](#resources-resource-define_calculation-custom_input-transform-using){: #resources-resource-define_calculation-custom_input-transform-using } | `(any -> any)` | | A function to use to transform the value. Must return `{:ok, value}` or `{:error, error}` |
361+
| [`using`](#resources-resource-define_calculation-custom_input-transform-using){: #resources-resource-define_calculation-custom_input-transform-using } | `(any -> any)` | | A function to use to transform the value. Must return `value` or `nil` |
362362

363363

364364

documentation/dsls/DSL-Ash.Resource.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ custom_input name, type
20612061
```
20622062

20632063

2064-
Define or customize an input to the action.
2064+
Define or customize an input to the action.
20652065

20662066
See the [code interface guide](/documentation/topics/resources/code-interfaces.md) for more.
20672067

@@ -2073,7 +2073,7 @@ See the [code interface guide](/documentation/topics/resources/code-interfaces.m
20732073
### Examples
20742074
```
20752075
custom_input :artist, :struct do
2076-
transform to: :artist_id, with: &{:ok, &1.id}
2076+
transform to: :artist_id, using: &(&1.id)
20772077
20782078
constraints instance_of: Artist
20792079
end
@@ -2109,17 +2109,17 @@ A transformation to be applied to the custom input.
21092109

21102110
### Examples
21112111
```
2112-
transform do
2112+
transform do
21132113
to :artist_id
2114-
with &{:ok, &1.id}
2114+
using &(&1.id)
21152115
end
21162116
21172117
```
21182118

21192119
```
2120-
transform do
2120+
transform do
21212121
to :points
2122-
with &try_parse_integer/1
2122+
using &try_parse_integer/1
21232123
end
21242124
21252125
```
@@ -2132,7 +2132,7 @@ end
21322132
| Name | Type | Default | Docs |
21332133
|------|------|---------|------|
21342134
| [`to`](#code_interface-define-custom_input-transform-to){: #code_interface-define-custom_input-transform-to } | `atom` | | A key to rewrite the argument to. If the custom input is also a required positional argument, then the `to` is automatically added to the `exclude_inputs` list. |
2135-
| [`using`](#code_interface-define-custom_input-transform-using){: #code_interface-define-custom_input-transform-using } | `(any -> any)` | | A function to use to transform the value. Must return `{:ok, value}` or `{:error, error}` |
2135+
| [`using`](#code_interface-define-custom_input-transform-using){: #code_interface-define-custom_input-transform-using } | `(any -> any)` | | A function to use to transform the value. Must return `value` or `nil` |
21362136

21372137

21382138

@@ -2201,7 +2201,7 @@ custom_input name, type
22012201
```
22022202

22032203

2204-
Define or customize an input to the action.
2204+
Define or customize an input to the action.
22052205

22062206
See the [code interface guide](/documentation/topics/resources/code-interfaces.md) for more.
22072207

@@ -2213,7 +2213,7 @@ See the [code interface guide](/documentation/topics/resources/code-interfaces.m
22132213
### Examples
22142214
```
22152215
custom_input :artist, :struct do
2216-
transform to: :artist_id, with: &{:ok, &1.id}
2216+
transform to: :artist_id, using: &(&1.id)
22172217
22182218
constraints instance_of: Artist
22192219
end
@@ -2249,17 +2249,17 @@ A transformation to be applied to the custom input.
22492249

22502250
### Examples
22512251
```
2252-
transform do
2252+
transform do
22532253
to :artist_id
2254-
with &{:ok, &1.id}
2254+
using &(&1.id)
22552255
end
22562256
22572257
```
22582258

22592259
```
2260-
transform do
2260+
transform do
22612261
to :points
2262-
with &try_parse_integer/1
2262+
using &try_parse_integer/1
22632263
end
22642264
22652265
```
@@ -2272,7 +2272,7 @@ end
22722272
| Name | Type | Default | Docs |
22732273
|------|------|---------|------|
22742274
| [`to`](#code_interface-define_calculation-custom_input-transform-to){: #code_interface-define_calculation-custom_input-transform-to } | `atom` | | A key to rewrite the argument to. If the custom input is also a required positional argument, then the `to` is automatically added to the `exclude_inputs` list. |
2275-
| [`using`](#code_interface-define_calculation-custom_input-transform-using){: #code_interface-define_calculation-custom_input-transform-using } | `(any -> any)` | | A function to use to transform the value. Must return `{:ok, value}` or `{:error, error}` |
2275+
| [`using`](#code_interface-define_calculation-custom_input-transform-using){: #code_interface-define_calculation-custom_input-transform-using } | `(any -> any)` | | A function to use to transform the value. Must return `value` or `nil` |
22762276

22772277

22782278

documentation/topics/resources/code-interfaces.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ MyApp.Blog.my_posts(stream?: true, actor: me)
163163
### Customizing the generated function
164164

165165
Often we want to have a slightly different interface when calling actions with functions,
166-
or we want to maintain backwards compatibility for callers of our code interface while
166+
or we want to maintain backwards compatibility for callers of our code interface while
167167
changing the underlying action implementation.
168168

169169
You can define `custom_input`s on your code interfaces to massage arguments from the function
@@ -194,11 +194,11 @@ define :follow_artist do
194194
to :artist_id
195195

196196
# Extracting the value using this function
197-
using fn
198-
%Ash.Union{type: :artist, value: value} ->
199-
{:ok, value.id}
197+
using fn
198+
%Ash.Union{type: :artist, value: value} ->
199+
value.id
200200
%Ash.Union{type: :artist_id, value: value} ->
201-
{:ok, value}
201+
value
202202
end
203203
end
204204
end
@@ -217,8 +217,8 @@ defmodule MyApp.Types.ArtistOrId do
217217
]
218218
]
219219

220-
def to_artist_id(%Ash.Union{type: :artist, value: artist}), do: {:ok, artist.id}
221-
def to_artist_id(%Ash.Union{type: :artist_id, value: artist_id}), do: {:ok, artist_id}
220+
def to_artist_id(%Ash.Union{type: :artist, value: artist}), do: artist.id
221+
def to_artist_id(%Ash.Union{type: :artist_id, value: artist_id}), do: artist_id
222222
end
223223
```
224224

lib/ash/resource/dsl.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -881,15 +881,15 @@ defmodule Ash.Resource.Dsl do
881881
""",
882882
examples: [
883883
"""
884-
transform do
884+
transform do
885885
to :artist_id
886-
with &{:ok, &1.id}
886+
using &(&1.id)
887887
end
888888
""",
889889
"""
890-
transform do
890+
transform do
891891
to :points
892-
with &try_parse_integer/1
892+
using &try_parse_integer/1
893893
end
894894
"""
895895
],
@@ -902,23 +902,22 @@ defmodule Ash.Resource.Dsl do
902902
],
903903
using: [
904904
type: {:fun, 1},
905-
doc:
906-
"A function to use to transform the value. Must return `{:ok, value}` or `{:error, error}`"
905+
doc: "A function to use to transform the value. Must return `value` or `nil`"
907906
]
908907
]
909908
}
910909

911910
@custom_input %Spark.Dsl.Entity{
912911
name: :custom_input,
913912
describe: """
914-
Define or customize an input to the action.
913+
Define or customize an input to the action.
915914
916915
See the [code interface guide](/documentation/topics/resources/code-interfaces.md) for more.
917916
""",
918917
examples: [
919918
"""
920919
custom_input :artist, :struct do
921-
transform to: :artist_id, with: &{:ok, &1.id}
920+
transform to: :artist_id, using: &(&1.id)
922921
923922
constraints instance_of: Artist
924923
end

0 commit comments

Comments
 (0)