Class: MR::Factory::RecordStack::RecordData

Inherits:
Object
  • Object
show all
Defined in:
lib/mr/factory/record_stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_datasObject (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

#recordObject (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_recordObject



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_recordObject



110
111
112
# File 'lib/mr/factory/record_stack.rb', line 110

def destroy_record
  @record.destroy unless @record.destroyed?
end

#record_classObject



95
96
97
# File 'lib/mr/factory/record_stack.rb', line 95

def record_class
  @record.class
end

#refresh_record_associationsObject

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