Class: Impersonator::Recording

Inherits:
Object
  • Object
show all
Includes:
HasLogger
Defined in:
lib/impersonator/recording.rb

Overview

A recording is responsible for saving interactions at record time, and replaying them at replay time.

A recording is always in one of two states.

The state objects are responsible of dealing with the recording logic, which happens in 3 moments:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasLogger

#logger

Constructor Details

#initialize(label, disabled: false, recordings_path:) ⇒ Recording

Returns a new instance of Recording.

Parameters:

  • label (String)
  • disabled (Boolean) (defaults to: false)

    true for always working in record mode. false by default

  • the (String)

    path to save recordings to



29
30
31
32
33
34
35
# File 'lib/impersonator/recording.rb', line 29

def initialize(label, disabled: false, recordings_path:)
  @label = label
  @recordings_path = recordings_path
  @disabled = disabled

  initialize_current_mode
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



24
25
26
# File 'lib/impersonator/recording.rb', line 24

def label
  @label
end

Instance Method Details

#finishObject

Finish a record/replay session.



56
57
58
59
# File 'lib/impersonator/recording.rb', line 56

def finish
  logger.debug "Recording #{label} finished"
  current_mode.finish
end

#invoke(impersonated_object, method, args) ⇒ Object

Handles the invocation of a given method on the impersonated object

It will either record the interaction or replay it dependening on if there is a recording available or not

Parameters:



51
52
53
# File 'lib/impersonator/recording.rb', line 51

def invoke(impersonated_object, method, args)
  current_mode.invoke(impersonated_object, method, args)
end

#record_mode?Boolean

Return whether it is currently at record mode

Returns:

  • (Boolean)


71
72
73
# File 'lib/impersonator/recording.rb', line 71

def record_mode?
  !replay_mode?
end

#replay_mode?Boolean

Return whether it is currently at replay mode

Returns:

  • (Boolean)


64
65
66
# File 'lib/impersonator/recording.rb', line 64

def replay_mode?
  @current_mode == replay_mode
end

#startObject

Start a recording/replay session



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

def start
  logger.debug "Starting recording #{label}..."
  current_mode.start
end