Class: Wee::State
Overview
This class is for backtracking the state of components (or decorations/presenters). Components that want an undo-facility to be implemented (triggered for example by a browsers back-button), have to overwrite the Component#state method. Class Wee::State simply represents a collection of objects from which snapshots were taken via methods take_snapshot.
Defined Under Namespace
Classes: Snapshot, SnapshotIVars
Instance Method Summary collapse
- #add(object) ⇒ Object (also: #<<)
- #add_ivar(object, ivar, value) ⇒ Object
-
#initialize ⇒ State
constructor
A new instance of State.
- #restore ⇒ Object
Constructor Details
Instance Method Details
#add(object) ⇒ Object Also known as: <<
20 21 22 |
# File 'lib/wee/state.rb', line 20 def add(object) @objects[object.object_id] ||= Snapshot.new(object, object.take_snapshot) end |
#add_ivar(object, ivar, value) ⇒ Object
24 25 26 |
# File 'lib/wee/state.rb', line 24 def add_ivar(object, ivar, value) (@objects_ivars[object.object_id] ||= SnapshotIVars.new(object, {})).ivars[ivar] = value end |
#restore ⇒ Object
30 31 32 33 34 35 |
# File 'lib/wee/state.rb', line 30 def restore @objects.each_value {|s| s.object.restore_snapshot(s.snapshot) } @objects_ivars.each_value {|s| s.ivars.each {|k,v| s.object.instance_variable_set(k, v) } } end |