Skip to content
Browse files

Simplify #build_hierarchy

  • Loading branch information...
1 parent e3e9ce6 commit 82208a100862cacb9a023e404ab33bf4f1861ae8 @joshuaclayton joshuaclayton committed Sep 14, 2012
Showing with 10 additions and 3 deletions.
  1. +9 −0 lib/factory_girl/definition_hierarchy.rb
  2. +1 −3 lib/factory_girl/factory.rb
View
9 lib/factory_girl/definition_hierarchy.rb
@@ -12,13 +12,20 @@ def to_create
FactoryGirl.to_create
end
+ 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
@@ -27,6 +34,7 @@ def self.build_constructor(&block)
end
end
end
+ private_class_method :build_constructor
def self.build_to_create(&block)
if block
@@ -35,5 +43,6 @@ def self.build_to_create(&block)
end
end
end
+ private_class_method :build_to_create
end
end
View
4 lib/factory_girl/factory.rb
@@ -121,9 +121,7 @@ def hierarchy_instance
end
def build_hierarchy
- hierarchy_class.build_to_create &definition.to_create
- hierarchy_class.build_constructor &definition.constructor
- hierarchy_class.add_callbacks definition.callbacks
+ hierarchy_class.build_from_definition definition
end
def callbacks

0 comments on commit 82208a1

Please sign in to comment.
Something went wrong with that request. Please try again.