1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
module FactoryBot
class DefinitionHierarchy
delegate :callbacks, :constructor, :to_create, to: Internal
def self.build_from_definition(definition)
build_to_create(&definition.to_create)
build_constructor(&definition.constructor)
add_callbacks definition.callbacks
end
def self.add_callbacks(callbacks)
if callbacks.any?
define_method :callbacks do
super() + callbacks
end
end
end
private_class_method :add_callbacks
def self.build_constructor(&block)
if block
define_method(:constructor) do
block
end
end
end
private_class_method :build_constructor
def self.build_to_create(&block)
if block
define_method(:to_create) do
block
end
end
end
private_class_method :build_to_create
end
end
|