Class: FactoryBot::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_bot/callback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, block) ⇒ Callback

Returns a new instance of Callback.



5
6
7
8
# File 'lib/factory_bot/callback.rb', line 5

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/factory_bot/callback.rb', line 3

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
21
# File 'lib/factory_bot/callback.rb', line 18

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

#run(instance, evaluator) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/factory_bot/callback.rb', line 10

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