Class: Impersonator::Recording
- Inherits:
-
Object
- Object
- Impersonator::Recording
- 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
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
-
#finish ⇒ Object
Finish a record/replay session.
-
#initialize(label, disabled: false, recordings_path:) ⇒ Recording
constructor
A new instance of Recording.
-
#invoke(impersonated_object, method, args) ⇒ Object
Handles the invocation of a given method on the impersonated object.
-
#record_mode? ⇒ Boolean
Return whether it is currently at record mode.
-
#replay_mode? ⇒ Boolean
Return whether it is currently at replay mode.
-
#start ⇒ Object
Start a recording/replay session.
Methods included from HasLogger
Constructor Details
#initialize(label, disabled: false, recordings_path:) ⇒ Recording
Returns a new instance of Recording.
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
#label ⇒ Object (readonly)
Returns the value of attribute label.
24 25 26 |
# File 'lib/impersonator/recording.rb', line 24 def label @label end |
Instance Method Details
#finish ⇒ Object
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
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
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
64 65 66 |
# File 'lib/impersonator/recording.rb', line 64 def replay_mode? @current_mode == replay_mode end |
#start ⇒ Object
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 |