2017-10-20 15:20:28 -04:00
|
|
|
module FactoryBot
|
2012-07-11 21:32:03 -04:00
|
|
|
class DefinitionHierarchy
|
2020-04-23 19:14:02 -04:00
|
|
|
delegate :callbacks, :constructor, :to_create, to: Internal
|
2012-07-11 21:32:03 -04:00
|
|
|
|
2012-09-14 08:22:28 -04:00
|
|
|
def self.build_from_definition(definition)
|
2013-01-18 13:27:30 -05:00
|
|
|
build_to_create(&definition.to_create)
|
|
|
|
build_constructor(&definition.constructor)
|
2012-09-14 08:22:28 -04:00
|
|
|
add_callbacks definition.callbacks
|
|
|
|
end
|
|
|
|
|
2012-07-11 21:32:03 -04:00
|
|
|
def self.add_callbacks(callbacks)
|
|
|
|
if callbacks.any?
|
|
|
|
define_method :callbacks do
|
|
|
|
super() + callbacks
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-09-14 08:22:28 -04:00
|
|
|
private_class_method :add_callbacks
|
2012-07-11 21:32:03 -04:00
|
|
|
|
|
|
|
def self.build_constructor(&block)
|
|
|
|
if block
|
|
|
|
define_method(:constructor) do
|
|
|
|
block
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-09-14 08:22:28 -04:00
|
|
|
private_class_method :build_constructor
|
2012-07-11 21:32:03 -04:00
|
|
|
|
|
|
|
def self.build_to_create(&block)
|
|
|
|
if block
|
|
|
|
define_method(:to_create) do
|
|
|
|
block
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-09-14 08:22:28 -04:00
|
|
|
private_class_method :build_to_create
|
2012-07-11 21:32:03 -04:00
|
|
|
end
|
|
|
|
end
|