Sha256: fc1fce6a36f54dc01e18da56d36aadabc73e024124968d64091dde5add879fb5

Contents?: true

Size: 542 Bytes

Versions: 7

Compression:

Stored size: 542 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.update_attribute(:record, object)
    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

7 entries across 7 versions & 1 rubygems

Version Path
memento-0.3.6 lib/memento/action/destroy.rb
memento-0.3.5 lib/memento/action/destroy.rb
memento-0.3.4 lib/memento/action/destroy.rb
memento-0.3.3 lib/memento/action/destroy.rb
memento-0.3.2 lib/memento/action/destroy.rb
memento-0.3.1 lib/memento/action/destroy.rb
memento-0.3.0 lib/memento/action/destroy.rb