Class: TCR::Cassette
- Inherits:
-
Object
- Object
- TCR::Cassette
- Defined in:
- lib/tcr/cassette.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #check_hits_all_sessions ⇒ Object
-
#initialize(name) ⇒ Cassette
constructor
A new instance of Cassette.
- #next_session ⇒ Object
- #recording? ⇒ Boolean
- #save ⇒ Object
Constructor Details
#initialize(name) ⇒ Cassette
Returns a new instance of Cassette.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tcr/cassette.rb', line 9 def initialize(name) @name = name if recording? verify_cassette_path_is_writable @sessions = [] else @sessions = unmarshal(File.read(filename)) end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/tcr/cassette.rb', line 7 def name @name end |
Instance Method Details
#check_hits_all_sessions ⇒ Object
43 44 45 |
# File 'lib/tcr/cassette.rb', line 43 def check_hits_all_sessions raise ExtraSessionsError if !recording? && !@sessions.empty? end |
#next_session ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tcr/cassette.rb', line 24 def next_session if recording? @sessions << [] @sessions.last else raise NoMoreSessionsError if @sessions.empty? @sessions.shift end end |
#recording? ⇒ Boolean
20 21 22 |
# File 'lib/tcr/cassette.rb', line 20 def recording? @recording ||= !File.exist?(filename) end |
#save ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/tcr/cassette.rb', line 35 def save return unless recording? File.write(filename, marshal(@sessions)) rescue Encoding::UndefinedConversionError File.binwrite(filename, marshal(@sessions)) end |