2010-06-24 09:45:57 -04:00
|
|
|
module FactoryGirl
|
2008-06-01 13:46:50 -04:00
|
|
|
|
2009-04-13 21:39:19 -04:00
|
|
|
# Raised when calling Factory.sequence from a dynamic attribute block
|
|
|
|
class SequenceAbuseError < StandardError; end
|
|
|
|
|
2009-02-17 16:38:15 -05:00
|
|
|
# Sequences are defined using Factory.sequence. Sequence values are generated
|
|
|
|
# using next.
|
2008-06-01 13:46:50 -04:00
|
|
|
class Sequence
|
|
|
|
|
2010-08-12 22:42:18 -04:00
|
|
|
def initialize(value = 1, &proc) #:nodoc:
|
2008-06-01 13:46:50 -04:00
|
|
|
@proc = proc
|
2010-07-06 20:54:55 -04:00
|
|
|
@value = value || 1
|
2008-06-01 13:46:50 -04:00
|
|
|
end
|
|
|
|
|
2008-07-30 15:47:12 -04:00
|
|
|
# Returns the next value for this sequence
|
2008-06-01 13:46:50 -04:00
|
|
|
def next
|
|
|
|
@proc.call(@value)
|
2010-08-12 22:42:18 -04:00
|
|
|
ensure
|
|
|
|
@value = @value.next
|
2008-06-01 13:46:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2008-12-11 15:54:33 -05:00
|
|
|
class << self
|
|
|
|
attr_accessor :sequences #:nodoc:
|
|
|
|
end
|
2008-07-30 15:47:12 -04:00
|
|
|
self.sequences = {}
|
2008-06-01 13:46:50 -04:00
|
|
|
end
|