Class: Geb::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(site, port, auto_build, debug) ⇒ Server

initialise the http server class with the site and port, use auto_build to start the file watcher.

Parameters:

  • site (Geb::Site)

    the site instance to serve

  • port (Integer)

    the port to run the server on

  • auto_build (Boolean)

    whether to start the file watcher

  • debug (Boolean)

    whether to enable full output during site rebuild



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/geb/server.rb', line 26

def initialize(site, port, auto_build, debug)

  # set the site and port
  @site = site
  @port = port
  @debug = debug

  # get the http server instance and file watcher if auto_build is set
  @http_server  = get_http_server()
  @file_watcher = auto_build ? get_file_watcher() : nil

  # initialize the http server and file watcher threads
  @http_server_thread  = nil
  @file_watcher_thread = nil

end

Instance Method Details

#startObject

start the http server and file watcher



44
45
46
47
48
49
50
51
52
# File 'lib/geb/server.rb', line 44

def start

  # start the http server in its own thread
  @http_server_thread  = Thread.new { @http_server.start }

  # start the file watcher if it is set in its own thread
  @file_watcher_thread = @file_watcher ? Thread.new { @file_watcher.start } : nil

end

#stopObject

stop the http server and file watcher



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/geb/server.rb', line 55

def stop

  # shutdown the http server
  Geb.log "Shutting down http server."
  @http_server.shutdown
  @http_server_thread.join

  # shutdown the file watcher
  Geb.log "Shutting down file watcher."  if @file_watcher
  @file_watcher.stop                     if @file_watcher
  @file_watcher_thread.join              if @file_watcher_thread

end