mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
20 lines
435 B
Ruby
20 lines
435 B
Ruby
module FactoryGirl
|
|
class Attribute #:nodoc:
|
|
|
|
class Dynamic < Attribute #:nodoc:
|
|
def initialize(name, block)
|
|
super(name)
|
|
@block = block
|
|
end
|
|
|
|
def add_to(proxy)
|
|
value = @block.arity == 1 ? @block.call(proxy) : proxy.instance_eval(&@block)
|
|
if FactoryGirl::Sequence === value
|
|
raise SequenceAbuseError
|
|
end
|
|
proxy.set(name, value)
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|