class FactoryBot::Attribute::Dynamic

@api private

Public Class Methods

new(name, ignored, block) click to toggle source
Calls superclass method FactoryBot::Attribute::new
# File lib/factory_bot/attribute/dynamic.rb, line 5
def initialize(name, ignored, block)
  super(name, ignored)
  @block = block
end

Public Instance Methods

to_proc() click to toggle source
# File lib/factory_bot/attribute/dynamic.rb, line 10
def to_proc
  block = @block

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

    value
  }
end