Class: Wee::Snapshot
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#backtrack_state method. Class Wee::Snapshot simply represents a collection of objects from which snapshots were taken via methods take_snapshot.
Instance Method Summary collapse
- #add(object) ⇒ Object
-
#initialize ⇒ Snapshot
constructor
A new instance of Snapshot.
- #restore ⇒ Object
Constructor Details
#initialize ⇒ Snapshot
Returns a new instance of Snapshot.
9 10 11 |
# File 'lib/wee/core/snapshot.rb', line 9 def initialize @objects = Hash.new end |
Instance Method Details
#add(object) ⇒ Object
13 14 15 16 |
# File 'lib/wee/core/snapshot.rb', line 13 def add(object) oid = object.object_id @objects[oid] = [object, object.take_snapshot] unless @objects.include?(oid) end |
#restore ⇒ Object
18 19 20 |
# File 'lib/wee/core/snapshot.rb', line 18 def restore @objects.each_value { |object, value| object.restore_snapshot(value) } end |