@api private
# File lib/factory_girl/attribute_list.rb, line 6 def initialize(name = nil, attributes = []) @name = name @attributes = attributes end
# File lib/factory_girl/attribute_list.rb, line 38 def apply_attributes(attributes_to_apply) attributes_to_apply.each {|attribute| add_attribute(attribute) } end
# File lib/factory_girl/attribute_list.rb, line 26 def associations AttributeList.new(@name, select(&:association?)) end
# File lib/factory_girl/attribute_list.rb, line 11 def define_attribute(attribute) ensure_attribute_not_self_referencing! attribute ensure_attribute_not_defined! attribute add_attribute attribute end
# File lib/factory_girl/attribute_list.rb, line 18 def each(&block) @attributes.each(&block) end
# File lib/factory_girl/attribute_list.rb, line 30 def ignored AttributeList.new(@name, select(&:ignored)) end
# File lib/factory_girl/attribute_list.rb, line 22 def names map(&:name) end
# File lib/factory_girl/attribute_list.rb, line 34 def non_ignored AttributeList.new(@name, reject(&:ignored)) end
# File lib/factory_girl/attribute_list.rb, line 44 def add_attribute(attribute) @attributes << attribute attribute end
# File lib/factory_girl/attribute_list.rb, line 61 def attribute_defined?(attribute_name) @attributes.any? do |attribute| attribute.name == attribute_name end end
# File lib/factory_girl/attribute_list.rb, line 49 def ensure_attribute_not_defined!(attribute) if attribute_defined?(attribute.name) raise AttributeDefinitionError, "Attribute already defined: #{attribute.name}" end end
# File lib/factory_girl/attribute_list.rb, line 55 def ensure_attribute_not_self_referencing!(attribute) if attribute.respond_to?(:factory) && attribute.factory == @name raise AssociationDefinitionError, "Self-referencing association '#{attribute.name}' in '#{attribute.factory}'" end end