Class: Memento::State

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.store(action_type, record) ⇒ Object



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

def self.store(action_type, record)
  new do |state|
    state.action_type = action_type.to_s
    state.record = record
    state.save if state.fetch?
  end
end

Instance Method Details

#fetch?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/memento/state.rb', line 38

def fetch?
  action.fetch?
end

#record_dataObject



29
30
31
# File 'lib/memento/state.rb', line 29

def record_data
  @record_data ||= Memento.serializer.load(read_attribute(:record_data))
end

#record_data=(data) ⇒ Object



33
34
35
36
# File 'lib/memento/state.rb', line 33

def record_data=(data)
  @record_data = nil
  write_attribute(:record_data, data.is_a?(String) ? data : Memento.serializer.dump(data))
end

#undoObject



25
26
27
# File 'lib/memento/state.rb', line 25

def undo
  Memento::Result.new(action.undo, self)
end