mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
28 lines
624 B
Ruby
28 lines
624 B
Ruby
module FactoryGirl
|
|
|
|
# Raised when calling Factory.sequence from a dynamic attribute block
|
|
class SequenceAbuseError < StandardError; end
|
|
|
|
# Sequences are defined using sequence within a FactoryGirl.define block.
|
|
# Sequence values are generated using next.
|
|
class Sequence
|
|
|
|
def initialize(value = 1, &proc) #:nodoc:
|
|
@proc = proc
|
|
@value = value || 1
|
|
end
|
|
|
|
# Returns the next value for this sequence
|
|
def next
|
|
@proc ? @proc.call(@value) : @value
|
|
ensure
|
|
@value = @value.next
|
|
end
|
|
|
|
end
|
|
|
|
class << self
|
|
attr_accessor :sequences #:nodoc:
|
|
end
|
|
self.sequences = {}
|
|
end
|