Class: MR::Factory::RecordStack::RecordData
- Inherits:
-
Object
- Object
- MR::Factory::RecordStack::RecordData
- Defined in:
- lib/mr/factory/record_stack.rb
Instance Attribute Summary collapse
-
#association_datas ⇒ Object
readonly
Returns the value of attribute association_datas.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #create_record ⇒ Object
- #destroy_record ⇒ Object
-
#initialize(record) ⇒ RecordData
constructor
A new instance of RecordData.
- #record_class ⇒ Object
-
#refresh_record_associations ⇒ Object
ensures records have their associations foreign type/key attributes set by re-setting the association to its current value.
- #set_association(name, record_data) ⇒ Object
Constructor Details
#initialize(record) ⇒ RecordData
Returns a new instance of RecordData.
90 91 92 93 |
# File 'lib/mr/factory/record_stack.rb', line 90 def initialize(record) @record = record @association_datas = build_association_datas(@record) end |
Instance Attribute Details
#association_datas ⇒ Object (readonly)
Returns the value of attribute association_datas.
88 89 90 |
# File 'lib/mr/factory/record_stack.rb', line 88 def association_datas @association_datas end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
88 89 90 |
# File 'lib/mr/factory/record_stack.rb', line 88 def record @record end |
Instance Method Details
#create_record ⇒ Object
103 104 105 106 107 108 |
# File 'lib/mr/factory/record_stack.rb', line 103 def create_record if @record.new_record? @record.save! @record.reset_save_called if @record.kind_of?(MR::FakeRecord) end end |
#destroy_record ⇒ Object
110 111 112 |
# File 'lib/mr/factory/record_stack.rb', line 110 def destroy_record @record.destroy unless @record.destroyed? end |
#record_class ⇒ Object
95 96 97 |
# File 'lib/mr/factory/record_stack.rb', line 95 def record_class @record.class end |
#refresh_record_associations ⇒ Object
ensures records have their associations foreign type/key attributes set by re-setting the association to its current value
116 117 118 119 120 121 |
# File 'lib/mr/factory/record_stack.rb', line 116 def refresh_record_associations @association_datas.each do |association_data| associated_record = @record.send(association_data.name) @record.send("#{association_data.name}=", associated_record) end end |
#set_association(name, record_data) ⇒ Object
99 100 101 |
# File 'lib/mr/factory/record_stack.rb', line 99 def set_association(name, record_data) @record.send("#{name}=", record_data.record) end |