Class: Betamax::MethodPlayer
- Inherits:
-
Object
- Object
- Betamax::MethodPlayer
- Defined in:
- lib/betamax/method_player.rb
Instance Attribute Summary collapse
-
#recording ⇒ Object
readonly
Returns the value of attribute recording.
Instance Method Summary collapse
- #call(method_name, *args, **kwargs) ⇒ Object
- #fully_consumed? ⇒ Boolean
-
#initialize(recording:) ⇒ MethodPlayer
constructor
A new instance of MethodPlayer.
- #unused_recordings ⇒ Object
Constructor Details
#initialize(recording:) ⇒ MethodPlayer
Returns a new instance of MethodPlayer.
5 6 7 8 |
# File 'lib/betamax/method_player.rb', line 5 def initialize recording: @recording = recording @playback_index = 0 end |
Instance Attribute Details
#recording ⇒ Object (readonly)
Returns the value of attribute recording.
3 4 5 |
# File 'lib/betamax/method_player.rb', line 3 def recording @recording end |
Instance Method Details
#call(method_name, *args, **kwargs) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/betamax/method_player.rb', line 23 def call(method_name, *args, **kwargs, &) record = advance_playback! method_name validate_method_name! record.method_name, method_name validate_args! method_name, args, record.args validate_kwargs! method_name, kwargs, record.kwargs validate_block! method_name, block_given?, record.block_given replay_yieldings(record.block_yieldings, &) record.result end |
#fully_consumed? ⇒ Boolean
10 11 12 13 |
# File 'lib/betamax/method_player.rb', line 10 def fully_consumed? @playback_index == @recording.size && @recording.all? { |record| nested_fully_consumed? record } end |
#unused_recordings ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/betamax/method_player.rb', line 15 def unused_recordings unused = @recording[@playback_index..] || [] nested_unused = @recording.first(@playback_index).flat_map do |record| unused_from_record record end unused + nested_unused end |