Sequences
A sequence is a named counter that yields a new value on every call. Use sequences when you want unique attribute values across factory builds — emails, login names, slugs.
Global sequences
Declare with .sequence inside a define block; consume with
ORM::Factory.generate:
1 2 3 4 5 6 7 | |
Without a block, a sequence returns its raw counter:
1 2 3 | |
Custom start value
:start controls the first value. Numeric starts increment with + 1;
string starts advance with .succ:
1 2 3 4 5 6 7 8 9 10 | |
Custom iterator
If a + 1 / .succ progression isn't enough, pass any Iterator and the
sequence pulls from it (with an optional block to transform each value):
1 2 3 4 5 | |
The sequence raises X::ORM::Factory::UsageError if the iterator is
exhausted.
Inline sequences (per-factory)
Declared inside a factory body, a sequence is bound as an attribute on that factory and advances on every build:
1 2 3 4 5 6 7 8 | |
Inline sequences are isolated per factory; they have no name in the global sequence registry.
Resetting counters
ORM::Factory.rewind-sequences resets every global sequence's counter back
to its :start. It is the standard between-tests cleanup for any spec that
asserts on sequence values:
1 2 3 | |
reload also clears the sequence registry along with factory definitions
and aliases.
Errors
| Exception | Trigger |
|---|---|
X::ORM::Factory::UnknownSequence |
generate on an unregistered name. |
X::ORM::Factory::DuplicateSequence |
Two .sequence 'x', … calls with the same name. |
X::ORM::Factory::UsageError |
Custom iterator exhausted. |