Permalink
Browse files

Reorganize #add_attribute

  • Loading branch information...
1 parent eb21a44 commit a50adda6c31b1b8fe929bb5be3e00e6125f577f0 @joshuaclayton joshuaclayton committed Oct 9, 2011
Showing with 6 additions and 8 deletions.
  1. +1 −0 lib/factory_girl/attribute_list.rb
  2. +5 −8 lib/factory_girl/definition_proxy.rb
@@ -13,6 +13,7 @@ def initialize
def declare_attribute(declaration)
@declarations << declaration
+ declaration
end
def define_attribute(attribute)
@@ -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)

0 comments on commit a50adda

Please sign in to comment.