Sha256: e585e0d052df5275feb8c59991bf4950569a8b1f192ab7b367f04a4534f62a0d

Contents?: true

Size: 541 Bytes

Versions: 1

Compression:

Stored size: 541 Bytes

Contents

class Memento::Action::Destroy < Memento::Action::Base
  
  def fetch
    record.attributes_for_memento
  end
  
  def undo
    rebuild_object do |object|
      begin
        object.save!
      rescue
        object.id = nil
        object.save!
      end
      state.record = object
      state.save
    end
  end
  
  private
  
  def rebuild_object
    new_object do |object|
      state.record_data.each do |attribute, value|
        object.send(:"#{attribute}=", value)
      end
      yield(object) if block_given?
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
memento-0.3.7 lib/memento/action/destroy.rb