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
Joe Ferris 5aea0f4096 Use a registry class for keeping factories and sequences. Treat
sequences largely like factories. Refactor name and aliases into a
common names method.
2011-01-27 20:15:33 -05:00

42 lines
953 B
Ruby

module FactoryGirl
# 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.
class Sequence
def initialize(name, value = 1, &proc) #:nodoc:
@name = name
@proc = proc
@value = value || 1
end
# Returns the next value for this sequence
def run(proxy_class = nil, overrides = {})
@proc ? @proc.call(@value) : @value
ensure
@value = @value.next
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
end
def self.sequences
puts "WARNING: FactoryGirl.sequences is deprecated."
puts "Use FactoryGirl.registry instead."
registry
end
end