Skip to content

Commit

Permalink
Clean up attribute_list
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Oct 15, 2011
1 parent 6e9baa7 commit 65fc7d7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/factory_girl/attribute_list.rb
Expand Up @@ -5,10 +5,10 @@ class AttributeList
attr_reader :callbacks, :declarations

def initialize
@attributes = {}
@attributes = {}
@declarations = []
@overridable = false
@callbacks = []
@callbacks = []
@overridable = false
end

def declare_attribute(declaration)
Expand All @@ -17,10 +17,7 @@ def declare_attribute(declaration)
end

def define_attribute(attribute)
if !overridable? && attribute_defined?(attribute.name)
raise AttributeDefinitionError, "Attribute already defined: #{attribute.name}"
end

ensure_attribute_not_defined! attribute
add_attribute attribute
end

Expand Down Expand Up @@ -90,6 +87,12 @@ def flattened_attributes
end.flatten
end

def ensure_attribute_not_defined!(attribute)
if !overridable? && attribute_defined?(attribute.name)
raise AttributeDefinitionError, "Attribute already defined: #{attribute.name}"
end
end

def attribute_defined?(attribute_name)
!!find_attribute(attribute_name)
end
Expand Down

0 comments on commit 65fc7d7

Please sign in to comment.