Skip to content

Commit

Permalink
Reorganize #add_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Oct 9, 2011
1 parent eb21a44 commit a50adda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/factory_girl/attribute_list.rb
Expand Up @@ -13,6 +13,7 @@ def initialize

def declare_attribute(declaration)
@declarations << declaration
declaration
end

def define_attribute(attribute)
Expand Down
13 changes: 5 additions & 8 deletions lib/factory_girl/definition_proxy.rb
Expand Up @@ -33,18 +33,15 @@ def initialize(factory, ignore = false)
# * 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)
Expand Down

0 comments on commit a50adda

Please sign in to comment.