Class: TCR::RecordableTCPSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/tcr/recordable_tcp_socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#liveObject (readonly)

Returns the value of attribute live.



8
9
10
# File 'lib/tcr/recordable_tcp_socket.rb', line 8

def live
  @live
end

#recordingObject

Returns the value of attribute recording.



9
10
11
# File 'lib/tcr/recordable_tcp_socket.rb', line 9

def recording
  @recording
end

#socketObject (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

#closeObject



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


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_ioObject



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