@@ -121,16 +121,8 @@ defmodule Ash.Subject do
121121 Ash.Query . set_context ( subject , map )
122122 end
123123
124- def set_context ( subject , nil ) , do: subject
125-
126- def set_context ( subject , map ) do
127- % {
128- subject
129- | context:
130- subject . context
131- |> Ash.Helpers . deep_merge_maps ( map )
132- |> then ( & Ash.Helpers . deep_merge_maps ( & 1 , map [ :shared ] || % { } ) )
133- }
124+ def set_context ( % Ash.ActionInput { } = subject , map ) do
125+ Ash.ActionInput . set_context ( subject , map )
134126 end
135127
136128 @ doc """
@@ -174,32 +166,24 @@ defmodule Ash.Subject do
174166 @ spec get_argument ( subject :: t ( ) , argument :: atom ( ) | binary ( ) , default :: term ( ) ) :: term ( )
175167 def get_argument ( subject , argument , default \\ nil )
176168
177- def get_argument ( subject , argument , default ) when is_atom ( argument ) do
178- value =
179- if Map . has_key? ( subject . arguments , argument ) do
180- Map . get ( subject . arguments , argument )
181- else
182- Map . get ( subject . arguments , to_string ( argument ) )
183- end
184-
185- if is_nil ( value ) do
186- default
187- else
188- value
169+ def get_argument ( % Ash.Changeset { } = subject , argument , default ) do
170+ case Ash.Changeset . get_argument ( subject , argument ) do
171+ nil -> default
172+ value -> value
189173 end
190174 end
191175
192- def get_argument ( subject , argument , default ) when is_binary ( argument ) do
193- subject . arguments
194- |> Enum . find ( fn { key , _ } ->
195- to_string ( key ) == argument
196- end )
197- |> case do
198- { _key , value } ->
199- value
176+ def get_argument ( % Ash.Query { } = subject , argument , default ) do
177+ case Ash.Query . get_argument ( subject , argument ) do
178+ nil -> default
179+ value -> value
180+ end
181+ end
200182
201- _ ->
202- default
183+ def get_argument ( % Ash.ActionInput { } = subject , argument , default ) do
184+ case Ash.ActionInput . get_argument ( subject , argument ) do
185+ nil -> default
186+ value -> value
203187 end
204188 end
205189
@@ -224,31 +208,16 @@ defmodule Ash.Subject do
224208 * `argument` - The argument name (atom or string)
225209 """
226210 @ spec fetch_argument ( subject :: t ( ) , argument :: atom ( ) | binary ( ) ) :: { :ok , term ( ) } | :error
227- def fetch_argument ( subject , argument ) when is_atom ( argument ) do
228- case Map . fetch ( subject . arguments , argument ) do
229- { :ok , value } ->
230- { :ok , value }
231-
232- :error ->
233- case Map . fetch ( subject . arguments , to_string ( argument ) ) do
234- { :ok , value } -> { :ok , value }
235- :error -> :error
236- end
237- end
211+ def fetch_argument ( % Ash.Changeset { } = subject , argument ) do
212+ Ash.Changeset . fetch_argument ( subject , argument )
238213 end
239214
240- def fetch_argument ( subject , argument ) when is_binary ( argument ) do
241- subject . arguments
242- |> Enum . find ( fn { key , _ } ->
243- to_string ( key ) == argument
244- end )
245- |> case do
246- { _key , value } ->
247- { :ok , value }
215+ def fetch_argument ( % Ash.Query { } = subject , argument ) do
216+ Ash.Query . fetch_argument ( subject , argument )
217+ end
248218
249- _ ->
250- :error
251- end
219+ def fetch_argument ( % Ash.ActionInput { } = subject , argument ) do
220+ Ash.ActionInput . fetch_argument ( subject , argument )
252221 end
253222
254223 @ doc """
@@ -310,12 +279,8 @@ defmodule Ash.Subject do
310279 Ash.Query . delete_argument ( subject , argument_or_arguments )
311280 end
312281
313- def delete_argument ( subject , argument_or_arguments ) do
314- argument_or_arguments
315- |> List . wrap ( )
316- |> Enum . reduce ( subject , fn argument , subject ->
317- % { subject | arguments: Map . delete ( subject . arguments , argument ) }
318- end )
282+ def delete_argument ( % Ash.ActionInput { } = subject , argument_or_arguments ) do
283+ Ash.ActionInput . delete_argument ( subject , argument_or_arguments )
319284 end
320285
321286 @ doc """
@@ -390,12 +355,8 @@ defmodule Ash.Subject do
390355 Ash.Query . before_action ( subject , callback , opts )
391356 end
392357
393- def before_action ( subject , callback , opts ) do
394- if opts [ :prepend? ] do
395- % { subject | before_action: [ callback | subject . before_action ] }
396- else
397- % { subject | before_action: subject . before_action ++ [ callback ] }
398- end
358+ def before_action ( % Ash.ActionInput { } = subject , callback , opts ) do
359+ Ash.ActionInput . before_action ( subject , callback , opts )
399360 end
400361
401362 @ doc """
@@ -424,12 +385,8 @@ defmodule Ash.Subject do
424385 Ash.Query . after_action ( subject , callback )
425386 end
426387
427- def after_action ( subject , callback , opts ) do
428- if opts [ :prepend? ] do
429- % { subject | after_action: [ callback | subject . after_action ] }
430- else
431- % { subject | after_action: subject . after_action ++ [ callback ] }
432- end
388+ def after_action ( % Ash.ActionInput { } = subject , callback , opts ) do
389+ Ash.ActionInput . after_action ( subject , callback , opts )
433390 end
434391
435392 @ doc """
@@ -490,12 +447,8 @@ defmodule Ash.Subject do
490447 Ash.Query . before_transaction ( subject , callback , opts )
491448 end
492449
493- def before_transaction ( subject , callback , opts ) do
494- if opts [ :prepend? ] do
495- % { subject | before_transaction: [ callback | subject . before_transaction ] }
496- else
497- % { subject | before_transaction: subject . before_transaction ++ [ callback ] }
498- end
450+ def before_transaction ( % Ash.ActionInput { } = subject , callback , opts ) do
451+ Ash.ActionInput . before_transaction ( subject , callback , opts )
499452 end
500453
501454 @ doc """
@@ -566,12 +519,8 @@ defmodule Ash.Subject do
566519 Ash.Query . after_transaction ( subject , callback , opts )
567520 end
568521
569- def after_transaction ( subject , callback , opts ) do
570- if opts [ :prepend? ] do
571- % { subject | after_transaction: [ callback | subject . after_transaction ] }
572- else
573- % { subject | after_transaction: subject . after_transaction ++ [ callback ] }
574- end
522+ def after_transaction ( % Ash.ActionInput { } = subject , callback , opts ) do
523+ Ash.ActionInput . after_transaction ( subject , callback , opts )
575524 end
576525
577526 @ doc """
@@ -652,11 +601,7 @@ defmodule Ash.Subject do
652601 Ash.Query . around_transaction ( subject , callback , opts )
653602 end
654603
655- def around_transaction ( subject , callback , opts ) do
656- if opts [ :prepend? ] do
657- % { subject | around_transaction: [ callback | subject . around_transaction ] }
658- else
659- % { subject | around_transaction: subject . around_transaction ++ [ callback ] }
660- end
604+ def around_transaction ( % Ash.ActionInput { } = subject , callback , opts ) do
605+ Ash.ActionInput . around_transaction ( subject , callback , opts )
661606 end
662607end
0 commit comments