2010-06-24 09:45:57 -04:00
|
|
|
module FactoryGirl
|
2012-05-05 02:31:31 -04:00
|
|
|
class Attribute
|
|
|
|
# @api private
|
|
|
|
class Dynamic < Attribute
|
2011-10-07 18:19:27 -04:00
|
|
|
def initialize(name, ignored, block)
|
|
|
|
super(name, ignored)
|
2009-01-02 17:33:00 -05:00
|
|
|
@block = block
|
|
|
|
end
|
|
|
|
|
2011-11-29 15:20:08 -05:00
|
|
|
def to_proc
|
2011-11-22 18:01:01 -05:00
|
|
|
block = @block
|
2011-10-07 18:19:27 -04:00
|
|
|
|
2012-04-20 16:59:39 -04:00
|
|
|
-> {
|
2013-06-07 10:42:50 -04:00
|
|
|
value = block.arity == 1 ? instance_exec(self, &block) : instance_exec(&block)
|
2011-11-22 18:01:01 -05:00
|
|
|
raise SequenceAbuseError if FactoryGirl::Sequence === value
|
|
|
|
value
|
|
|
|
}
|
2009-01-02 17:33:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|