1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/lib/factory_bot/definition_hierarchy.rb

39 lines
872 B
Ruby
Raw Normal View History

module FactoryBot
class DefinitionHierarchy
delegate :callbacks, :constructor, :to_create, to: Internal
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
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
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
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
end
end