2017-10-20 15:20:28 -04:00
|
|
|
module FactoryBot
|
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
|
|
|
-> {
|
2015-04-15 21:59:13 -04:00
|
|
|
value = case block.arity
|
|
|
|
when 1, -1 then instance_exec(self, &block)
|
|
|
|
else instance_exec(&block)
|
2020-06-05 15:15:18 -04:00
|
|
|
end
|
2017-10-20 15:20:28 -04:00
|
|
|
raise SequenceAbuseError if FactoryBot::Sequence === value
|
2019-05-12 22:39:55 -04:00
|
|
|
|
2011-11-22 18:01:01 -05:00
|
|
|
value
|
|
|
|
}
|
2009-01-02 17:33:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|