Class: TCR::RecordableTCPSocket
- Inherits:
-
Object
- Object
- TCR::RecordableTCPSocket
- Defined in:
- lib/tcr/recordable_tcp_socket.rb
Instance Attribute Summary collapse
-
#live ⇒ Object
readonly
Returns the value of attribute live.
-
#recording ⇒ Object
Returns the value of attribute recording.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #gets(*args) ⇒ Object
-
#initialize(address, port, cassette) ⇒ RecordableTCPSocket
constructor
A new instance of RecordableTCPSocket.
- #print(str) ⇒ Object
- #read(bytes) ⇒ Object
- #read_nonblock(*args) ⇒ Object
- #setsockopt(*args) ⇒ Object
- #to_io ⇒ Object
- #write(str) ⇒ Object
Constructor Details
#initialize(address, port, cassette) ⇒ RecordableTCPSocket
Returns a new instance of RecordableTCPSocket.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 11 def initialize(address, port, cassette) raise TCR::NoCassetteError.new unless TCR.cassette @read_lock = Queue.new if cassette.recording? @live = true @socket = TCPSocket.real_open(address, port) else @live = false end @recording = cassette.next_session end |
Instance Attribute Details
#live ⇒ Object (readonly)
Returns the value of attribute live.
8 9 10 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 8 def live @live end |
#recording ⇒ Object
Returns the value of attribute recording.
9 10 11 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 9 def recording @recording end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
8 9 10 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 8 def socket @socket end |
Instance Method Details
#close ⇒ Object
60 61 62 63 64 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 60 def close if live @socket.close end end |
#closed? ⇒ Boolean
52 53 54 55 56 57 58 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 52 def closed? if live @socket.closed? else false end end |
#gets(*args) ⇒ Object
29 30 31 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 29 def gets(*args) _read(:gets, *args) end |
#print(str) ⇒ Object
37 38 39 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 37 def print(str) _write(:print, str) end |
#read(bytes) ⇒ Object
25 26 27 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 25 def read(bytes) _read(:read, bytes) end |
#read_nonblock(*args) ⇒ Object
33 34 35 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 33 def read_nonblock(*args) _read(:read_nonblock, *args, blocking: false) end |
#setsockopt(*args) ⇒ Object
66 67 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 66 def setsockopt(*args) end |
#to_io ⇒ Object
46 47 48 49 50 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 46 def to_io if live @socket.to_io end end |
#write(str) ⇒ Object
41 42 43 44 |
# File 'lib/tcr/recordable_tcp_socket.rb', line 41 def write(str) _write(:write, str) str.length end |