Class: Impersonator::RecordMode
- Inherits:
-
Object
- Object
- Impersonator::RecordMode
- Includes:
- HasLogger
- Defined in:
- lib/impersonator/record_mode.rb
Overview
The state of a recording in record mode
Instance Attribute Summary collapse
-
#recording_path ⇒ Object
readonly
recording file path.
Instance Method Summary collapse
-
#finish ⇒ Object
Finishes the record session.
-
#initialize(recording_path) ⇒ RecordMode
constructor
A new instance of RecordMode.
-
#invoke(impersonated_object, method, args) ⇒ Object
Records the method invocation.
-
#start ⇒ Object
Start a recording session.
Methods included from HasLogger
Constructor Details
#initialize(recording_path) ⇒ RecordMode
Returns a new instance of RecordMode.
10 11 12 |
# File 'lib/impersonator/record_mode.rb', line 10 def initialize(recording_path) @recording_path = recording_path end |
Instance Attribute Details
#recording_path ⇒ Object (readonly)
recording file path
7 8 9 |
# File 'lib/impersonator/record_mode.rb', line 7 def recording_path @recording_path end |
Instance Method Details
#finish ⇒ Object
Finishes the record session
34 35 36 37 38 |
# File 'lib/impersonator/record_mode.rb', line 34 def finish File.open(recording_path, 'w') do |file| YAML.dump(@method_invocations, file) end end |
#invoke(impersonated_object, method, args) ⇒ Object
Records the method invocation
26 27 28 29 30 31 |
# File 'lib/impersonator/record_mode.rb', line 26 def invoke(impersonated_object, method, args) spiable_block = method&.block_spy&.block impersonated_object.send(method.name, *args, &spiable_block).tap do |return_value| record(method, return_value) end end |
#start ⇒ Object
Start a recording session
15 16 17 18 19 |
# File 'lib/impersonator/record_mode.rb', line 15 def start logger.debug 'Recording mode' make_sure_recordings_dir_exists @method_invocations = [] end |