Class: Reactive::MetaModel::ActiveRecordInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord_meta_model.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance) ⇒ ActiveRecordInstance

Returns a new instance of ActiveRecordInstance.



20
21
22
# File 'lib/activerecord_meta_model.rb', line 20

def initialize(instance)
  @instance = instance
end

Instance Method Details

#revertObject

reload without hitting the database does not trigger observers



26
27
28
29
30
31
32
# File 'lib/activerecord_meta_model.rb', line 26

def revert
  @instance.instance_variable_set(:@marked_for_destruction, false)
  @instance.changes.each {|attr, (old,new)| @instance.send("#{attr}=", old) }
  @instance.send(:changed_attributes).clear
  @instance.class.meta.has_manys.each {|assoc_meta| @instance.send(assoc_meta.name).each {|record| record.supra.revert} }
  @instance.class.meta.has_ones.each {|assoc_meta| revert_assoc(@instance.send(assoc_meta.name)) }
end