Sha256: b5981c33bb6425e52ea0c1441f1b2b1d2306264738e002b305294f761598be53

Contents?: true

Size: 530 Bytes

Versions: 2

Compression:

Stored size: 530 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, -2 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-6.2.1 lib/factory_bot/attribute/dynamic.rb
factory_bot-6.2.0 lib/factory_bot/attribute/dynamic.rb