Class: Memento::Session

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/memento/session.rb

Instance Method Summary collapse

Instance Method Details

#add_state(action_type, record) ⇒ Object



12
13
14
# File 'lib/memento/session.rb', line 12

def add_state(action_type, record)
  states.store(action_type, record)
end

#undoObject



16
17
18
19
20
21
22
23
# File 'lib/memento/session.rb', line 16

def undo
  states.map(&:undo).inject(Memento::ResultArray.new) do |results, result|
    result.state.destroy if result.success?
    results << result
  end
ensure
  destroy if states.count.zero?
end

#undo!Object



25
26
27
28
29
30
31
# File 'lib/memento/session.rb', line 25

def undo!
  transaction do
    undo.tap do |results|
      raise Memento::ErrorOnRewind if results.failed?
    end
  end
end