AshDispatch.Resource.Info (AshDispatch v0.5.1)
View SourceIntrospection helpers for AshDispatch.Resource.
Provides functions to query event configurations from resources at runtime.
Usage
# Get all events for a resource
events = AshDispatch.Resource.Info.events(MyApp.Orders.ProductOrder)
# Get a specific event by name
event = AshDispatch.Resource.Info.event(MyApp.Orders.ProductOrder, :created)
# Get event options
event_id = AshDispatch.Resource.Info.event_id(event)
trigger_on = AshDispatch.Resource.Info.trigger_on(event)
channels = AshDispatch.Resource.Info.channels(event)Generated Functions
This module uses Spark.InfoGenerator to automatically generate helper functions
for querying the dispatch section and its entities.
Resource-level:
events(resource)- Returns all events defined in the resource
Event entity getters:
name(event)- Get event nametrigger_on(event)- Get action names that trigger this eventmodule(event)- Get callback module (if any)event_id(event)- Get event IDdomain(event)- Get event domainload(event)- Get relationships to preloadchannels(event)- Get channel configurationscontent(event)- Get content configurationmetadata(event)- Get metadata configuration
Examples
# Find events triggered by specific action
iex> events = AshDispatch.Resource.Info.events(ProductOrder)
iex> Enum.filter(events, fn event ->
...> :create in List.wrap(AshDispatch.Resource.Info.trigger_on(event))
...> end)
[%AshDispatch.Resource.Dsl.Event{name: :created, ...}]
# Get all event IDs for a resource
iex> events = AshDispatch.Resource.Info.events(ProductOrder)
iex> Enum.map(events, &AshDispatch.Resource.Info.event_id/1)
["product_order.created", "product_order.cancelled"]
# Check if event has callback module
iex> event = AshDispatch.Resource.Info.event(ProductOrder, :created)
iex> if AshDispatch.Resource.Info.module(event) do
...> "Uses callback module"
...> else
...> "Uses inline config"
...> end
"Uses inline config"
Summary
Functions
Get a specific counter by name.
Get all counters defined in a resource.
dispatch DSL entities
Check if a resource has the AshDispatch.Resource extension.
Get entity_changes configuration for a resource, if any.
Check if entity change broadcasting is enabled for a resource.
Get a specific event by name.
Count total events for a resource.
Get all event IDs for a resource.
Get all events defined in a resource.
Get all events that trigger on a specific action.
Get all events that use callback modules.
Get all events that use inline configuration.
Get resource_meta configuration for a resource, if any.
Functions
Get a specific counter by name.
Parameters
resource- The resource modulename- The counter name (atom)
Returns
%AshDispatch.Resource.Dsl.Counter{}if foundnilif not found
Examples
iex> AshDispatch.Resource.Info.counter(ProductOrder, :pending_orders_counter)
%AshDispatch.Resource.Dsl.Counter{name: :pending_orders_counter, ...}
Get all counters defined in a resource.
Parameters
resource- The resource module
Returns
List of %AshDispatch.Resource.Dsl.Counter{} structs
Examples
iex> AshDispatch.Resource.Info.counters(ProductOrder)
[%AshDispatch.Resource.Dsl.Counter{name: :pending_orders_counter, ...}]
dispatch DSL entities
Check if a resource has the AshDispatch.Resource extension.
Parameters
resource- The resource module
Returns
trueif resource uses AshDispatch.Resourcefalseotherwise
Examples
iex> AshDispatch.Resource.Info.dispatch_enabled?(ProductOrder)
true
iex> AshDispatch.Resource.Info.dispatch_enabled?(SomeOtherResource)
false
Get entity_changes configuration for a resource, if any.
Returns the %AshDispatch.Resource.Dsl.EntityChanges{} struct if
entity_changes true is defined in the dispatch section, or nil.
Check if entity change broadcasting is enabled for a resource.
Get a specific event by name.
Parameters
resource- The resource modulename- The event name (atom)
Returns
%AshDispatch.Resource.Dsl.Event{}if foundnilif not found
Examples
iex> AshDispatch.Resource.Info.event(ProductOrder, :created)
%AshDispatch.Resource.Dsl.Event{name: :created, ...}
iex> AshDispatch.Resource.Info.event(ProductOrder, :nonexistent)
nil
Count total events for a resource.
Parameters
resource- The resource module
Returns
Integer count of events
Examples
iex> AshDispatch.Resource.Info.event_count(ProductOrder)
3
Get all event IDs for a resource.
Parameters
resource- The resource module
Returns
List of event ID strings
Examples
iex> AshDispatch.Resource.Info.event_ids(ProductOrder)
["product_order.created", "product_order.cancelled", "product_order.shipped"]
Get all events defined in a resource.
Parameters
resource- The resource module
Returns
List of %AshDispatch.Resource.Dsl.Event{} structs
Examples
iex> AshDispatch.Resource.Info.events(ProductOrder)
[%AshDispatch.Resource.Dsl.Event{name: :created, ...}]
Get all events that trigger on a specific action.
Parameters
resource- The resource moduleaction_name- The action name (atom)
Returns
List of %AshDispatch.Resource.Dsl.Event{} structs
Examples
iex> AshDispatch.Resource.Info.events_for_action(ProductOrder, :create)
[%AshDispatch.Resource.Dsl.Event{name: :created, trigger_on: :create}]
iex> AshDispatch.Resource.Info.events_for_action(ProductOrder, :update)
[]
Get all events that use callback modules.
Parameters
resource- The resource module
Returns
List of %AshDispatch.Resource.Dsl.Event{} structs that have a module defined
Examples
iex> AshDispatch.Resource.Info.events_with_modules(ProductOrder)
[%AshDispatch.Resource.Dsl.Event{name: :complex_event, module: MyApp.Events.Complex}]
Get all events that use inline configuration.
Parameters
resource- The resource module
Returns
List of %AshDispatch.Resource.Dsl.Event{} structs that use inline config
Examples
iex> AshDispatch.Resource.Info.inline_events(ProductOrder)
[%AshDispatch.Resource.Dsl.Event{name: :created, module: nil, channels: [...]}]
Get resource_meta configuration for a resource, if any.
Returns the %AshDispatch.Resource.Dsl.ResourceMeta{} struct if
resource_meta is defined in the dispatch section, or nil.