Class: FactoryBot::Sequence Private
- Inherits:
-
Object
- Object
- FactoryBot::Sequence
- Defined in:
- lib/factory_bot/sequence.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Sequences are defined using sequence within a FactoryBot.define block. Sequence values are generated using next.
Defined Under Namespace
Classes: EnumeratorAdapter
Instance Attribute Summary collapse
- #name ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(name, *args, &proc) ⇒ Sequence
constructor
private
A new instance of Sequence.
- #names ⇒ Object private
- #next(scope = nil) ⇒ Object private
- #rewind ⇒ Object private
Constructor Details
#initialize(name, *args, &proc) ⇒ Sequence
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Sequence.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/factory_bot/sequence.rb', line 8 def initialize(name, *args, &proc) @name = name @proc = proc = args. @value = args.first || 1 @aliases = .fetch(:aliases) { [] } unless @value.respond_to?(:peek) @value = EnumeratorAdapter.new(@value) end end |
Instance Attribute Details
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
6 7 8 |
# File 'lib/factory_bot/sequence.rb', line 6 def name @name end |
Instance Method Details
#names ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/factory_bot/sequence.rb', line 33 def names [@name] + @aliases end |
#next(scope = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/factory_bot/sequence.rb', line 21 def next(scope = nil) if @proc && scope scope.instance_exec(value, &@proc) elsif @proc @proc.call(value) else value end ensure increment_value end |
#rewind ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 |
# File 'lib/factory_bot/sequence.rb', line 37 def rewind @value.rewind end |