Class: Capybara::Webkit::Connection
- Inherits:
-
Object
- Object
- Capybara::Webkit::Connection
- Defined in:
- lib/capybara/webkit/connection.rb
Constant Summary collapse
- SERVER_PATH =
File.("../../../../bin/webkit_server", __FILE__)
- WEBKIT_SERVER_START_TIMEOUT =
15
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #gets ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #print(string) ⇒ Object
- #puts(string) ⇒ Object
- #read(length) ⇒ Object
- #restart ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/capybara/webkit/connection.rb', line 13 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 if .has_key?(:stderr) @output_target = [:stderr] elsif .has_key?(:stdout) warn '[DEPRECATION] The Capybara::Webkit::Connection `stdout` option ' \ 'is deprecated. Please use `stderr` instead.' @output_target = [:stdout] else @output_target = $stderr end start_server connect end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
11 12 13 |
# File 'lib/capybara/webkit/connection.rb', line 11 def pid @pid end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/capybara/webkit/connection.rb', line 11 def port @port end |
Instance Method Details
#gets ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/capybara/webkit/connection.rb', line 43 def gets response = "" until response.match(/\n/) do response += read(1) end response end |
#print(string) ⇒ Object
39 40 41 |
# File 'lib/capybara/webkit/connection.rb', line 39 def print(string) @socket.print string end |
#puts(string) ⇒ Object
35 36 37 |
# File 'lib/capybara/webkit/connection.rb', line 35 def puts(string) @socket.puts string end |
#read(length) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/capybara/webkit/connection.rb', line 51 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
64 65 66 67 68 |
# File 'lib/capybara/webkit/connection.rb', line 64 def restart @socket = nil start_server connect end |