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.



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

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.



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

def custom_host
  @custom_host
end

#fixed_portObject (readonly)

Returns the value of attribute fixed_port.



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

def fixed_port
  @fixed_port
end

#socketObject (readonly)

Returns the value of attribute socket.



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

def socket
  @socket
end

#timeoutObject

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

Instance Method Details

#hostObject



18
19
20
# File 'lib/capybara/poltergeist/server.rb', line 18

def host
  @socket.host
end

#portObject



14
15
16
# File 'lib/capybara/poltergeist/server.rb', line 14

def port
  @socket.port
end

#restartObject



34
35
36
37
# File 'lib/capybara/poltergeist/server.rb', line 34

def restart
  stop
  start
end

#send(command) ⇒ Object



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

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



26
27
28
# File 'lib/capybara/poltergeist/server.rb', line 26

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

#stopObject



30
31
32
# File 'lib/capybara/poltergeist/server.rb', line 30

def stop
  @socket.close
end