mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Simplify attribute and callback calculation by extracting order of processing to separate method
This commit is contained in:
parent
9cee12a8dc
commit
f37c888c63
2 changed files with 8 additions and 10 deletions
|
@ -19,9 +19,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def apply_attributes(attributes_to_apply)
|
||||
attributes_to_apply.each do |attribute|
|
||||
add_attribute(attribute) unless attribute_defined?(attribute.name)
|
||||
end
|
||||
attributes_to_apply.each {|attribute| add_attribute(attribute) }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -95,27 +95,27 @@ module FactoryGirl
|
|||
|
||||
def class_name #:nodoc:
|
||||
@class_name || parent.class_name || name
|
||||
|
||||
end
|
||||
|
||||
def attributes
|
||||
compile
|
||||
AttributeList.new(@name).tap do |list|
|
||||
traits.each do |trait|
|
||||
list.apply_attributes(trait.attributes)
|
||||
processing_order.each do |factory|
|
||||
list.apply_attributes factory.attributes
|
||||
end
|
||||
|
||||
list.apply_attributes(@definition.attributes)
|
||||
list.apply_attributes(parent.attributes)
|
||||
end
|
||||
end
|
||||
|
||||
def callbacks
|
||||
[parent.callbacks, traits.map(&:callbacks).reverse, @definition.callbacks].flatten
|
||||
processing_order.map {|factory| factory.callbacks }.flatten
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def processing_order
|
||||
[parent, traits.reverse, @definition].flatten
|
||||
end
|
||||
|
||||
def assert_valid_options(options)
|
||||
options.assert_valid_keys(:class, :parent, :default_strategy, :aliases, :traits)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue