Class: FactoryGirl::Sequence

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_girl/sequence.rb

Overview

Sequences are defined using sequence within a FactoryGirl.define block. Sequence values are generated using next.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = 1, &proc) ⇒ Sequence

:nodoc:



8
9
10
11
12
# File 'lib/factory_girl/sequence.rb', line 8

def initialize(name, value = 1, &proc) #:nodoc:
  @name  = name
  @proc  = proc
  @value = value
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/factory_girl/sequence.rb', line 6

def name
  @name
end

Instance Method Details

#default_strategyObject



20
21
22
# File 'lib/factory_girl/sequence.rb', line 20

def default_strategy
  :create
end

#namesObject



24
25
26
# File 'lib/factory_girl/sequence.rb', line 24

def names
  [@name]
end

#nextObject



14
15
16
17
18
# File 'lib/factory_girl/sequence.rb', line 14

def next
  @proc ? @proc.call(@value) : @value
ensure
  @value = @value.next
end