Class: FactoryGirl::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_girl/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
9
# File 'lib/factory_girl/callback.rb', line 5

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
22
# File 'lib/factory_girl/callback.rb', line 19

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

#run(instance, evaluator) ⇒ Object



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

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