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

29 lines
581 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(value = 1, &proc) #:nodoc:
2008-06-01 13:46:50 -04:00
@proc = proc
@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)
ensure
@value = @value.next
2008-06-01 13:46:50 -04:00
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