Class: Rapid::Server::Service

Inherits:
Rapid::Services::Service show all
Defined in:
lib/ury_rapid/server/service.rb

Overview

Object for launching the Rapid server.

This object exposes a DSL to the Rapid configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*_) ⇒ Service

Returns a new instance of Service


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ury_rapid/server/service.rb', line 12

def initialize(*_)
  super

  @rack        = 'thin'
  @host        = '0.0.0.0'
  @port        = 8181
  @root        = '/'
  @config      = {}

  check_server_em_compatible
end

Instance Attribute Details

#root=(value) ⇒ Object (writeonly) Also known as: url_root

Sets the URL root of the server


31
32
33
# File 'lib/ury_rapid/server/service.rb', line 31

def root=(value)
  @root = value
end

Instance Method Details

#file_root(root) ⇒ Object

Sets the file system root of the server


35
36
37
# File 'lib/ury_rapid/server/service.rb', line 35

def file_root(root)
  @config[:root_directory] = root
end

#host(address, port) ⇒ Object

Sets the host address and port of the server


25
26
27
28
# File 'lib/ury_rapid/server/service.rb', line 25

def host(address, port)
  @host = address
  @port = port
end

#runvoid

This method returns an undefined value.

Starts the server

This should be called within an EventMachine instance.


44
45
46
47
48
# File 'lib/ury_rapid/server/service.rb', line 44

def run
  Rack::Server.start(
    app: dispatch, server: @rack, Host: @host, Port: @port
  )
end