Class: Capybara::Webkit::Connection
- Inherits:
-
Object
- Object
- Capybara::Webkit::Connection
- Defined in:
- lib/capybara/webkit/connection.rb
Instance Method Summary collapse
- #gets ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #pid ⇒ Object
- #port ⇒ Object
- #print(string) ⇒ Object
- #puts(string) ⇒ Object
- #read(length) ⇒ Object
- #restart ⇒ Object
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( = {}) @socket = nil if .has_key?(:socket_class) warn '[DEPRECATION] The Capybara::Webkit::Connection `socket_class` ' \ 'option is deprecated without replacement.' @socket_class = [:socket_class] else @socket_class = TCPSocket end @server = [:server] start_server connect end |
Instance Method Details
#gets ⇒ Object
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 |
#pid ⇒ Object
60 61 62 |
# File 'lib/capybara/webkit/connection.rb', line 60 def pid @server.pid end |
#port ⇒ Object
56 57 58 |
# File 'lib/capybara/webkit/connection.rb', line 56 def port @server.port end |
#print(string) ⇒ Object
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 |
#restart ⇒ Object
50 51 52 53 54 |
# File 'lib/capybara/webkit/connection.rb', line 50 def restart @socket = nil start_server connect end |