Class: FactoryBot::Attribute::Dynamic Private

Inherits:
FactoryBot::Attribute show all
Defined in:
lib/factory_bot/attribute/dynamic.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.

API:

  • private

Instance Attribute Summary

Attributes inherited from FactoryBot::Attribute

#ignored, #name

Instance Method Summary collapse

Methods inherited from FactoryBot::Attribute

#alias_for?, #association?

Constructor Details

#initialize(name, ignored, block) ⇒ Dynamic

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 Dynamic.

API:

  • private



5
6
7
8
# File 'lib/factory_bot/attribute/dynamic.rb', line 5

def initialize(name, ignored, block)
  super(name, ignored)
  @block = block
end

Instance Method Details

#to_procObject

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.

API:

  • private



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/factory_bot/attribute/dynamic.rb', line 10

def to_proc
  block = @block

  -> {
    value = case block.arity
            when 1, -1 then instance_exec(self, &block)
            else instance_exec(&block)
            end
    raise SequenceAbuseError if FactoryBot::Sequence === value
    value
  }
end