1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
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, -2 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
|