class FactoryBot::AttributeList
@api private
Public Class Methods
new(name = nil, attributes = [])
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 6 def initialize(name = nil, attributes = []) @name = name @attributes = attributes end
Public Instance Methods
apply_attributes(attributes_to_apply)
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 38 def apply_attributes(attributes_to_apply) attributes_to_apply.each { |attribute| add_attribute(attribute) } end
associations()
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 26 def associations AttributeList.new(@name, select(&:association?)) end
define_attribute(attribute)
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 11 def define_attribute(attribute) ensure_attribute_not_self_referencing! attribute ensure_attribute_not_defined! attribute add_attribute attribute end
each(&block)
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 18 def each(&block) @attributes.each(&block) end
ignored()
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 30 def ignored AttributeList.new(@name, select(&:ignored)) end
names()
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 22 def names map(&:name) end
non_ignored()
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 34 def non_ignored AttributeList.new(@name, reject(&:ignored)) end
Private Instance Methods
add_attribute(attribute)
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 44 def add_attribute(attribute) @attributes << attribute attribute end
attribute_defined?(attribute_name)
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 62 def attribute_defined?(attribute_name) @attributes.any? do |attribute| attribute.name == attribute_name end end
ensure_attribute_not_defined!(attribute)
click to toggle source
# File lib/factory_bot/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
ensure_attribute_not_self_referencing!(attribute)
click to toggle source
# File lib/factory_bot/attribute_list.rb, line 55 def ensure_attribute_not_self_referencing!(attribute) if attribute.respond_to?(:factory) && attribute.factory == @name message = "Self-referencing association '#{attribute.name}' in '#{attribute.factory}'" raise AssociationDefinitionError, message end end