Class: FactoryGirl::AttributeList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/factory_girl/attribute_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ AttributeList

Returns a new instance of AttributeList.



5
6
7
8
# File 'lib/factory_girl/attribute_list.rb', line 5

def initialize(name = nil)
  @name       = name
  @attributes = []
end

Instance Method Details

#apply_attributes(attributes_to_apply) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/factory_girl/attribute_list.rb', line 21

def apply_attributes(attributes_to_apply)
  new_attributes = []

  attributes_to_apply.each do |attribute|
    new_attribute = find_attribute(attribute.name) || attribute
    delete_attribute(attribute.name)
    new_attributes << new_attribute
  end

  prepend_attributes new_attributes
end

#define_attribute(attribute) ⇒ Object



10
11
12
13
14
15
# File 'lib/factory_girl/attribute_list.rb', line 10

def define_attribute(attribute)
  ensure_attribute_not_self_referencing! attribute
  ensure_attribute_not_defined! attribute

  add_attribute attribute
end

#each(&block) ⇒ Object



17
18
19
# File 'lib/factory_girl/attribute_list.rb', line 17

def each(&block)
  sorted_attributes.each(&block)
end