Sha256: 87b68d4f1e1a7886edb0ba6da196521d9855c1401d9a79471a3397d755eb0228

Contents?: true

Size: 534 Bytes

Versions: 2

Compression:

Stored size: 534 Bytes

Contents

module FactoryBot
  class Attribute
    # @api private
    class Dynamic < Attribute
      def initialize(name, ignored, block)
        super(name, ignored)
        @block = block
      end

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
factory_bot-5.2.0 lib/factory_bot/attribute/dynamic.rb
factory_bot-5.1.2 lib/factory_bot/attribute/dynamic.rb