2010-06-24 09:45:57 -04:00
|
|
|
module FactoryGirl
|
2009-01-02 17:33:00 -05:00
|
|
|
class Attribute #:nodoc:
|
|
|
|
class Dynamic < Attribute #:nodoc:
|
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
|
|
|
-> {
|
2011-11-28 22:52:54 -05:00
|
|
|
value = block.arity == 1 ? block.call(self) : 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
|