Module: Mongoid::Undo

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

Constant Summary collapse

VERSION =
'1.0.0'

Instance Method Summary collapse

Instance Method Details

#undoObject Also known as: redo



39
40
41
42
43
44
45
46
47
48
# File 'lib/mongoid/undo.rb', line 39

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)


51
52
53
54
55
56
57
58
# File 'lib/mongoid/undo.rb', line 51

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