2017-10-20 15:20:28 -04:00
|
|
|
module FactoryBot
|
2011-09-23 13:14:02 -04:00
|
|
|
class Declaration
|
2012-05-05 02:31:31 -04:00
|
|
|
# @api private
|
2011-09-23 13:14:02 -04:00
|
|
|
class Implicit < Declaration
|
2011-10-07 18:19:27 -04:00
|
|
|
def initialize(name, factory = nil, ignored = false)
|
|
|
|
super(name, ignored)
|
2011-09-23 13:14:02 -04:00
|
|
|
@factory = factory
|
|
|
|
end
|
|
|
|
|
2011-10-14 15:14:43 -04:00
|
|
|
def ==(other)
|
2018-10-21 17:14:46 -04:00
|
|
|
self.class == other.class &&
|
|
|
|
name == other.name &&
|
2011-10-14 15:14:43 -04:00
|
|
|
factory == other.factory &&
|
|
|
|
ignored == other.ignored
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
2018-09-27 21:35:05 -04:00
|
|
|
|
2011-10-14 15:14:43 -04:00
|
|
|
attr_reader :factory
|
|
|
|
|
2011-09-23 13:14:02 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def build
|
2017-10-20 15:20:28 -04:00
|
|
|
if FactoryBot.factories.registered?(name)
|
2011-09-23 13:14:02 -04:00
|
|
|
[Attribute::Association.new(name, name, {})]
|
2019-04-26 15:48:37 -04:00
|
|
|
elsif FactoryBot::Internal.sequences.registered?(name)
|
2011-10-07 18:19:27 -04:00
|
|
|
[Attribute::Sequence.new(name, name, @ignored)]
|
2019-09-10 19:24:20 -04:00
|
|
|
elsif @factory.name.to_s == name.to_s
|
|
|
|
message = "Self-referencing trait '#{@name}'"
|
|
|
|
raise TraitDefinitionError, message
|
2011-09-23 13:14:02 -04:00
|
|
|
else
|
2011-10-28 23:01:50 -04:00
|
|
|
@factory.inherit_traits([name])
|
|
|
|
[]
|
2011-09-23 13:14:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|