module Mongoid::Undo

Constants

VERSION

Public Instance Methods

redo()
Alias for: undo
redoable?()
Alias for: undoable?
undo() click to toggle source
# File lib/mongoid/undo.rb, line 43
def undo
  run_callbacks __callee__ do
    case action
    when :create, :destroy
      deleted_at.present? ? restore : delete
    when :update
      retrieve
    end
  end
end
Also aliased as: redo
undoable?() click to toggle source
# File lib/mongoid/undo.rb, line 55
def undoable?
  case action
  when :create, :destroy
    true
  when :update
    read_attribute(:version).to_i > @version
  end
end
Also aliased as: redoable?

Private Instance Methods

retrieve() click to toggle source

@todo Remove Mongoid 4 support.

# File lib/mongoid/undo.rb, line 67
def retrieve
  attributes = versions.last.versioned_attributes.except('version', 'updated_at')
  respond_to?(:update_one) ? update_one(attributes) : update(attributes)
end