Class: Geb::CLI::Commands::Server

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/geb/commands/server.rb

Overview

Define server command

Instance Method Summary collapse

Instance Method Details

#call(**options) ⇒ Object

Call method for the server command

Parameters:

  • options (Hash)

    the options hash for the command



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/geb/commands/server.rb', line 33

def call(**options)

  # initialise a site and load it from the current directory
  site = Geb::Site.new
  site.load(Dir.pwd)

  # build the site if the skip_build option is not set
  site.build() unless options[:skip_build]

  # start a new queue for the shutdown signal (instead of using trap to shutdown the server and file watcher directly)
  @shutdown_queue = Queue.new
  trap('INT') { @shutdown_queue << :shutdown }

  # get the server port from the options, site configuration or auto generated (0), in that order
  server_port = options[:port] || site.site_config.local_port || 0

  # initialize the server
  server = Geb::Server.new(site, server_port, !options[:skip_auto_build], options[:debug])

  # start the server
  server.start()

  # wait for the shutdown signal
  @shutdown_queue.pop

  # stop the server
  server.stop()

rescue Geb::Error => e

  # print error message
  puts
  warn e.message

end

#force_shutdownObject

Force shutdown of the server



70
71
72
# File 'lib/geb/commands/server.rb', line 70

def force_shutdown
  @shutdown_queue << :shutdown if @shutdown_queue
end