Class: Camcorder::Recording

Inherits:
Object
  • Object
show all
Defined in:
lib/camcorder/recording.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Recording

Returns a new instance of Recording.



8
9
10
11
# File 'lib/camcorder/recording.rb', line 8

def initialize(&block)
  @value = nil
  @behavior = nil
end

Instance Attribute Details

#behaviorObject (readonly)

Returns the value of attribute behavior.



6
7
8
# File 'lib/camcorder/recording.rb', line 6

def behavior
  @behavior
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/camcorder/recording.rb', line 5

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/camcorder/recording.rb', line 39

def ==(other)
  YAML.dump(self) == YAML.dump(other)
end

#deep_clone(value) ⇒ Object



35
36
37
# File 'lib/camcorder/recording.rb', line 35

def deep_clone(value)
  YAML.load(YAML.dump(value))
end

#record(&block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/camcorder/recording.rb', line 13

def record(&block)
  res = yield
  # Make sure we store a copy of the result so future destructive mutations
  # do not change this value
  @value = deep_clone(res)
  @behavior = :return
  res
rescue Exception => e
  @value = e
  @behavior = :raise
  raise e
end

#replayObject



26
27
28
29
30
31
32
33
# File 'lib/camcorder/recording.rb', line 26

def replay
  case @behavior
  when :return
    return @value
  when :raise
    raise @value
  end
end