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
624 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
# Sequences are defined using sequence within a FactoryGirl.define block.
# 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 ? @proc.call(@value) : @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