1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/lib/factory_girl/sequence.rb

28 lines
541 B
Ruby
Raw Normal View History

module FactoryGirl
2008-06-01 13:46:50 -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
def initialize(&proc) #:nodoc:
2008-06-01 13:46:50 -04:00
@proc = proc
@value = 0
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
@value += 1
@proc.call(@value)
end
end
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