Class: Wee::State::Snapshot

Inherits:
Object show all
Defined in:
lib/wee/state.rb

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Snapshot

Returns a new instance of Snapshot.



13
14
15
16
17
18
# File 'lib/wee/state.rb', line 13

def initialize(object)
  @object = object
  @snapshot = nil
  @has_snapshot = false
  @ivars = nil
end

Instance Method Details

#add_ivar(ivar, value) ⇒ Object



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

def add_ivar(ivar, value)
  @ivars ||= {}
  @ivars[ivar] = value
end

#restoreObject



30
31
32
33
# File 'lib/wee/state.rb', line 30

def restore
  @object.restore_snapshot(@snapshot) if @has_snapshot
  @ivars.each_pair {|k,v| @object.instance_variable_set(k, v) } if @ivars
end

#takeObject



20
21
22
23
# File 'lib/wee/state.rb', line 20

def take
  @snapshot = @object.take_snapshot unless @has_snapshot
  @has_snapshot = true
end