Sha256: 697e59f2149f5d7b312aefc979dffab59bddb161cf6b0b95b68c257d77f2daf6

Contents?: true

Size: 526 Bytes

Versions: 4

Compression:

Stored size: 526 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

4 entries across 4 versions & 1 rubygems

Version Path
factory_bot-6.1.0 lib/factory_bot/attribute/dynamic.rb
factory_bot-6.0.2 lib/factory_bot/attribute/dynamic.rb
factory_bot-6.0.1 lib/factory_bot/attribute/dynamic.rb
factory_bot-6.0.0 lib/factory_bot/attribute/dynamic.rb