Class: Capybara::Webkit::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/webkit/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/capybara/webkit/connection.rb', line 7

def initialize(options = {})
  @socket = nil
  if options.has_key?(:socket_class)
    warn '[DEPRECATION] The Capybara::Webkit::Connection `socket_class` ' \
      'option is deprecated without replacement.'
    @socket_class = options[:socket_class]
  else
    @socket_class = TCPSocket
  end
  @server = options[:server]
  start_server
  connect
end

Instance Method Details

#getsObject



29
30
31
32
33
34
35
# File 'lib/capybara/webkit/connection.rb', line 29

def gets
  response = ""
  until response.match(/\n/) do
    response += read(1)
  end
  response
end

#pidObject



60
61
62
# File 'lib/capybara/webkit/connection.rb', line 60

def pid
  @server.pid
end

#portObject



56
57
58
# File 'lib/capybara/webkit/connection.rb', line 56

def port
  @server.port
end


25
26
27
# File 'lib/capybara/webkit/connection.rb', line 25

def print(string)
  @socket.print string
end

#puts(string) ⇒ Object



21
22
23
# File 'lib/capybara/webkit/connection.rb', line 21

def puts(string)
  @socket.puts string
end

#read(length) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/capybara/webkit/connection.rb', line 37

def read(length)
  response = ""
  begin
    while response.length < length do
      response += @socket.read_nonblock(length - response.length)
    end
  rescue IO::WaitReadable
    Thread.new { IO.select([@socket]) }.join
    retry
  end
  response
end

#restartObject



50
51
52
53
54
# File 'lib/capybara/webkit/connection.rb', line 50

def restart
  @socket = nil
  start_server
  connect
end