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
Instance Method Summary collapse
- #add(object) ⇒ Object (also: #<<)
- #add_ivar(object, ivar, value = object.instance_variable_get(ivar)) ⇒ Object
-
#initialize ⇒ State
constructor
A new instance of State.
- #restore ⇒ Object
Constructor Details
Instance Method Details
#add(object) ⇒ Object Also known as: <<
40 41 42 |
# File 'lib/wee/state.rb', line 40 def add(object) (@snapshots[object.object_id] ||= Snapshot.new(object)).take end |
#add_ivar(object, ivar, value = object.instance_variable_get(ivar)) ⇒ Object
44 45 46 |
# File 'lib/wee/state.rb', line 44 def add_ivar(object, ivar, value=object.instance_variable_get(ivar)) (@snapshots[object.object_id] ||= Snapshot.new(object)).add_ivar(ivar, value) end |
#restore ⇒ Object
50 51 52 |
# File 'lib/wee/state.rb', line 50 def restore @snapshots.each_value {|snapshot| snapshot.restore} end |