Class: MR::Factory::RecordStack::AssociationData
- Inherits:
-
Object
- Object
- MR::Factory::RecordStack::AssociationData
- Defined in:
- lib/mr/factory/record_stack.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#preset_record_data ⇒ Object
readonly
Returns the value of attribute preset_record_data.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #get_record_data(factory_config, lookup) ⇒ Object
-
#initialize(association) ⇒ AssociationData
constructor
A new instance of AssociationData.
- #name ⇒ Object
- #preset? ⇒ Boolean
- #record_class ⇒ Object
- #required?(factory_config) ⇒ Boolean
Constructor Details
#initialize(association) ⇒ AssociationData
Returns a new instance of AssociationData.
137 138 139 140 141 142 |
# File 'lib/mr/factory/record_stack.rb', line 137 def initialize(association) @association = association preset_record = association.owner.send("#{self.name}") @preset_record_data = RecordData.new(preset_record) if preset_record end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
135 136 137 |
# File 'lib/mr/factory/record_stack.rb', line 135 def association @association end |
#preset_record_data ⇒ Object (readonly)
Returns the value of attribute preset_record_data.
135 136 137 |
# File 'lib/mr/factory/record_stack.rb', line 135 def preset_record_data @preset_record_data end |
Instance Method Details
#<=>(other) ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/mr/factory/record_stack.rb', line 172 def <=>(other) if other.kind_of?(self.class) self.name.to_s <=> other.name.to_s else super end end |
#get_record_data(factory_config, lookup) ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/mr/factory/record_stack.rb', line 162 def get_record_data(factory_config, lookup) if self.preset? self.preset_record_data elsif (lookup_record_data = get_lookup_record_data(factory_config, lookup)) lookup_record_data else RecordData.new(build_record(factory_config)) end end |
#name ⇒ Object
144 145 146 |
# File 'lib/mr/factory/record_stack.rb', line 144 def name self.association.reflection.name end |
#preset? ⇒ Boolean
152 153 154 |
# File 'lib/mr/factory/record_stack.rb', line 152 def preset? !self.preset_record_data.nil? end |
#record_class ⇒ Object
148 149 150 |
# File 'lib/mr/factory/record_stack.rb', line 148 def record_class self.association.klass end |
#required?(factory_config) ⇒ Boolean
156 157 158 159 160 |
# File 'lib/mr/factory/record_stack.rb', line 156 def required?(factory_config) self.preset? || factory_config.force_in_stack_association?(self.name) || columns_required?(self.association) end |