Module: Mongoid::Undo

Extended by:
ActiveSupport::Concern
Includes:
Callbacks, Paranoia, Versioning
Defined in:
lib/mongoid/undo.rb,
lib/mongoid/undo/version.rb

Constant Summary collapse

VERSION =
'0.11.0'

Instance Method Summary collapse

Instance Method Details

#undoObject Also known as: redo



35
36
37
38
39
40
41
42
43
44
# File 'lib/mongoid/undo.rb', line 35

def undo
  run_callbacks __callee__ do
    case action
    when :create, :destroy
      deleted_at.present? ? restore : delete
    when :update
      retrieve
    end
  end
end

#undoable?Boolean Also known as: redoable?

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
# File 'lib/mongoid/undo.rb', line 47

def undoable?
  case action
  when :create, :destroy
    true
  when :update
    read_attribute(:version).to_i > @version
  end
end