Class: FactoryGirl::Callback

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

Constant Summary collapse

VALID_NAMES =
[:after_build, :after_create, :after_stub].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, block) ⇒ Callback

Returns a new instance of Callback.



7
8
9
10
11
# File 'lib/factory_girl/callback.rb', line 7

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

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
24
# File 'lib/factory_girl/callback.rb', line 21

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

#run(instance, proxy) ⇒ Object



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

def run(instance, proxy)
  case block.arity
  when 1 then block.call(instance)
  when 2 then block.call(instance, proxy)
  else block.call
  end
end