Class: FactoryGirl::Attribute::Dynamic

Inherits:
FactoryGirl::Attribute show all
Defined in:
lib/factory_girl/attribute/dynamic.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from FactoryGirl::Attribute

#ignored, #name

Instance Method Summary collapse

Methods inherited from FactoryGirl::Attribute

#alias_for?, #association?

Constructor Details

#initialize(name, ignored, block) ⇒ Dynamic

Returns a new instance of Dynamic.



4
5
6
7
# File 'lib/factory_girl/attribute/dynamic.rb', line 4

def initialize(name, ignored, block)
  super(name, ignored)
  @block = block
end

Instance Method Details

#to_procObject



9
10
11
12
13
14
15
16
17
# File 'lib/factory_girl/attribute/dynamic.rb', line 9

def to_proc
  block = @block

  lambda {
    value = block.arity == 1 ? block.call(self) : instance_exec(&block)
    raise SequenceAbuseError if FactoryGirl::Sequence === value
    value
  }
end