2010-06-24 09:45:57 -04:00
|
|
|
module FactoryGirl
|
2008-06-01 13:46:50 -04:00
|
|
|
|
2011-01-26 20:55:06 -05:00
|
|
|
# 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
|
2012-04-06 14:41:13 -04:00
|
|
|
attr_reader :name
|
2011-05-19 10:56:45 -04:00
|
|
|
|
2012-04-06 14:41:13 -04:00
|
|
|
def initialize(name, *args, &proc) #:nodoc:
|
|
|
|
@name = name
|
|
|
|
@proc = proc
|
|
|
|
|
|
|
|
options = args.extract_options!
|
|
|
|
@value = args.first || 1
|
2012-05-05 01:14:21 -04:00
|
|
|
@aliases = options.fetch(:aliases) { [] }
|
2008-06-01 13:46:50 -04:00
|
|
|
end
|
|
|
|
|
2011-05-19 10:56:45 -04:00
|
|
|
def next
|
2011-01-27 16:25:31 -05:00
|
|
|
@proc ? @proc.call(@value) : @value
|
2010-08-12 22:42:18 -04:00
|
|
|
ensure
|
|
|
|
@value = @value.next
|
2008-06-01 13:46:50 -04:00
|
|
|
end
|
2012-04-06 14:41:13 -04:00
|
|
|
|
|
|
|
def names
|
|
|
|
[@name] + @aliases
|
|
|
|
end
|
2008-06-01 13:46:50 -04:00
|
|
|
end
|
|
|
|
end
|