Class: Capybara::Poltergeist::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/poltergeist/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fixed_port = nil, timeout = nil, custom_host = nil) ⇒ Server

Returns a new instance of Server.



5
6
7
8
9
10
# File 'lib/capybara/poltergeist/server.rb', line 5

def initialize(fixed_port = nil, timeout = nil, custom_host = nil)
  @fixed_port = fixed_port
  @timeout    = timeout
  @custom_host = custom_host
  start
end

Instance Attribute Details

#custom_hostObject (readonly)

Returns the value of attribute custom_host.



3
4
5
# File 'lib/capybara/poltergeist/server.rb', line 3

def custom_host
  @custom_host
end

#fixed_portObject (readonly)

Returns the value of attribute fixed_port.



3
4
5
# File 'lib/capybara/poltergeist/server.rb', line 3

def fixed_port
  @fixed_port
end

#socketObject (readonly)

Returns the value of attribute socket.



3
4
5
# File 'lib/capybara/poltergeist/server.rb', line 3

def socket
  @socket
end

#timeoutObject

Returns the value of attribute timeout.



3
4
5
# File 'lib/capybara/poltergeist/server.rb', line 3

def timeout
  @timeout
end

Instance Method Details

#hostObject



16
17
18
# File 'lib/capybara/poltergeist/server.rb', line 16

def host
  @socket.host
end

#portObject



12
13
14
# File 'lib/capybara/poltergeist/server.rb', line 12

def port
  @socket.port
end

#restartObject



32
33
34
35
# File 'lib/capybara/poltergeist/server.rb', line 32

def restart
  stop
  start
end

#send(command) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/capybara/poltergeist/server.rb', line 37

def send(command)
  receive_timeout = nil # default
  if command.name == 'visit'
    command.args.push(timeout) # set the client set visit timeout parameter
    receive_timeout = timeout + 5 # Add a couple of seconds to let the client timeout first
  end
  @socket.send(command.id, command.message, receive_timeout) or raise DeadClient.new(command.message)
end

#startObject



24
25
26
# File 'lib/capybara/poltergeist/server.rb', line 24

def start
  @socket = WebSocketServer.new(fixed_port, timeout, custom_host)
end

#stopObject



28
29
30
# File 'lib/capybara/poltergeist/server.rb', line 28

def stop
  @socket.close
end