Skip to content

Commit

Permalink
Simplify #build_hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Sep 14, 2012
1 parent e3e9ce6 commit 82208a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/factory_girl/definition_hierarchy.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -35,5 +43,6 @@ def self.build_to_create(&block)
end
end
end
private_class_method :build_to_create
end
end
4 changes: 1 addition & 3 deletions lib/factory_girl/factory.rb
Expand Up @@ -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
Expand Down

0 comments on commit 82208a1

Please sign in to comment.