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

43 lines
953 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(name, value = 1, &proc) #:nodoc:
@name = name
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
def run(proxy_class = nil, overrides = {})
@proc ? @proc.call(@value) : @value
ensure
@value = @value.next
2008-06-01 13:46:50 -04:00
end
def next
puts "WARNING: FactoryGirl::Sequence#next is deprecated."
puts "Use #run instead."
run
end
def default_strategy
:create
end
def names
[@name]
end
2008-06-01 13:46:50 -04:00
end
def self.sequences
puts "WARNING: FactoryGirl.sequences is deprecated."
puts "Use FactoryGirl.registry instead."
registry
end
2008-06-01 13:46:50 -04:00
end