Sha256: 5fc3f6881450a47f095061d33e0ff51be803339cebe119025d0ceec7b9e36179

Contents?: true

Size: 629 Bytes

Versions: 4

Compression:

Stored size: 629 Bytes

Contents

module FactoryBot
  class Callback
    attr_reader :name

    def initialize(name, block)
      @name = name.to_sym
      @block = block
    end

    def run(instance, evaluator)
      case block.arity
      when 1, -1 then syntax_runner.instance_exec(instance, &block)
      when 2 then syntax_runner.instance_exec(instance, evaluator, &block)
      else syntax_runner.instance_exec(&block)
      end
    end

    def ==(other)
      name == other.name &&
        block == other.block
    end

    protected

    attr_reader :block

    private

    def syntax_runner
      @syntax_runner ||= SyntaxRunner.new
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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