Sha256: 7be8fbd64fc45c47f98ad1e4a713b809c47319cfecaaafe19871a8166559dd8b

Contents?: true

Size: 533 Bytes

Versions: 13

Compression:

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

13 entries across 13 versions & 1 rubygems

Version Path
factory_bot-5.1.1 lib/factory_bot/attribute/dynamic.rb
factory_bot-5.1.0 lib/factory_bot/attribute/dynamic.rb
factory_bot-5.0.2 lib/factory_bot/attribute/dynamic.rb
factory_bot-5.0.1 lib/factory_bot/attribute/dynamic.rb
factory_bot-5.0.0 lib/factory_bot/attribute/dynamic.rb
factory_bot-5.0.0.rc2 lib/factory_bot/attribute/dynamic.rb
factory_bot-5.0.0.rc1 lib/factory_bot/attribute/dynamic.rb
factory_bot-4.11.1 lib/factory_bot/attribute/dynamic.rb
factory_bot-4.11.0 lib/factory_bot/attribute/dynamic.rb
factory_bot-4.10.0 lib/factory_bot/attribute/dynamic.rb
factory_bot-4.8.2 lib/factory_bot/attribute/dynamic.rb
factory_bot-1.0.1.alpha lib/factory_bot/attribute/dynamic.rb
factory_bot-1.0.0.alpha lib/factory_bot/attribute/dynamic.rb