Class: FactoryGirl::AttributeList
- Inherits:
-
Object
- Object
- FactoryGirl::AttributeList
- Includes:
- Enumerable
- Defined in:
- lib/factory_girl/attribute_list.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#declarations ⇒ Object
readonly
Returns the value of attribute declarations.
Instance Method Summary collapse
- #add_callback(callback) ⇒ Object
- #apply_attributes(attributes_to_apply) ⇒ Object
- #declare_attribute(declaration) ⇒ Object
- #define_attribute(attribute) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ AttributeList
constructor
A new instance of AttributeList.
- #overridable ⇒ Object
- #overridable? ⇒ Boolean
- #size ⇒ Object
Constructor Details
#initialize ⇒ AttributeList
Returns a new instance of AttributeList.
7 8 9 10 11 12 |
# File 'lib/factory_girl/attribute_list.rb', line 7 def initialize @attributes = {} @declarations = [] @overridable = false @callbacks = [] end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
5 6 7 |
# File 'lib/factory_girl/attribute_list.rb', line 5 def callbacks @callbacks end |
#declarations ⇒ Object (readonly)
Returns the value of attribute declarations.
5 6 7 |
# File 'lib/factory_girl/attribute_list.rb', line 5 def declarations @declarations end |
Instance Method Details
#add_callback(callback) ⇒ Object
27 28 29 |
# File 'lib/factory_girl/attribute_list.rb', line 27 def add_callback(callback) @callbacks << callback end |
#apply_attributes(attributes_to_apply) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/factory_girl/attribute_list.rb', line 35 def apply_attributes(attributes_to_apply) attributes_to_apply.callbacks.reverse.each { |callback| prepend_callback(callback) } new_attributes = [] attributes_to_apply.each do |attribute| new_attribute = if !overridable? && defined_attribute = find_attribute(attribute.name) defined_attribute else attribute end delete_attribute(attribute.name) new_attributes << new_attribute end prepend_attributes new_attributes end |
#declare_attribute(declaration) ⇒ Object
14 15 16 17 |
# File 'lib/factory_girl/attribute_list.rb', line 14 def declare_attribute(declaration) @declarations << declaration declaration end |
#define_attribute(attribute) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/factory_girl/attribute_list.rb', line 19 def define_attribute(attribute) if !overridable? && attribute_defined?(attribute.name) raise AttributeDefinitionError, "Attribute already defined: #{attribute.name}" end add_attribute attribute end |
#each(&block) ⇒ Object
31 32 33 |
# File 'lib/factory_girl/attribute_list.rb', line 31 def each(&block) flattened_attributes.each(&block) end |
#overridable ⇒ Object
53 54 55 |
# File 'lib/factory_girl/attribute_list.rb', line 53 def overridable @overridable = true end |
#overridable? ⇒ Boolean
57 58 59 |
# File 'lib/factory_girl/attribute_list.rb', line 57 def overridable? @overridable end |
#size ⇒ Object
61 62 63 |
# File 'lib/factory_girl/attribute_list.rb', line 61 def size to_a.size end |