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

Reorganize #add_attribute

This commit is contained in:
Joshua Clayton 2011-10-09 17:14:40 -04:00
parent eb21a449de
commit a50adda6c3
2 changed files with 6 additions and 8 deletions

View file

@ -13,6 +13,7 @@ module FactoryGirl
def declare_attribute(declaration)
@declarations << declaration
declaration
end
def define_attribute(attribute)

View file

@ -33,18 +33,15 @@ module FactoryGirl
# * value: +Object+
# If no block is given, this value will be used for this attribute.
def add_attribute(name, value = nil, &block)
if block_given?
if value
raise AttributeDefinitionError, "Both value and block given"
else
declaration = Declaration::Dynamic.new(name, @ignore, block)
end
raise AttributeDefinitionError, "Both value and block given" if value && block_given?
declaration = if block_given?
Declaration::Dynamic.new(name, @ignore, block)
else
declaration = FactoryGirl::Declaration::Static.new(name, value, @ignore)
Declaration::Static.new(name, value, @ignore)
end
@factory.declare_attribute(declaration)
declaration
end
def ignore(&block)