AshScenario.Sequence (ash_scenario v0.6.0)

View Source

Manages sequence counters for runtime attribute evaluation.

Automatically started and managed internally when MFA tuples are used in prototype attribute definitions.

Usage

Sequences are automatically incremented when prototypes use MFA tuples:

prototype :user do
  attr :email, {MyModule, :unique_email, []}
end

Each attribute gets its own sequence based on the key {resource_module, prototype_ref, attr_name}.

Sequences are automatically reset between tests when using ExUnit.

Summary

Functions

Returns a specification to start this module under a supervisor.

Get the next value in a sequence for a given key.

Reset all sequences to their initial state.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

next(key)

Get the next value in a sequence for a given key.

The key is typically {resource_module, prototype_ref, attr_name}.

Examples

iex> AshScenario.Sequence.next({User, :test_user, :email})
0
iex> AshScenario.Sequence.next({User, :test_user, :email})
1
iex> AshScenario.Sequence.next({User, :test_user, :username})
0

reset()

Reset all sequences to their initial state.

This is automatically called in test setups to ensure test isolation.

Examples

setup do
  AshScenario.Sequence.reset()
  :ok
end