Class: Codebot::WebServer

Inherits:
ThreadController show all
Extended by:
Sanitizers
Defined in:
lib/codebot/web_server.rb

Overview

This class manages a WebListener that runs in a separate thread.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sanitizers

valid!, valid_boolean, valid_channel_key, valid_channel_name, valid_endpoint, valid_host, valid_identifier, valid_network, valid_port, valid_secret, valid_string

Methods inherited from ThreadController

#join, #running?, #start, #start!, #stop, #stop!

Constructor Details

#initialize(core) ⇒ WebServer

Creates a new web server.

Parameters:

  • core (Core)

    the bot this server belongs to



17
18
19
# File 'lib/codebot/web_server.rb', line 17

def initialize(core)
  @core = core
end

Class Method Details

.configurationProc

Creates a Proc for configuring this web server.

Returns:

  • (Proc)

    the proc



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/codebot/web_server.rb', line 29

def self.configuration
  server = self
  proc do
    disable :traps
    set :bind, ENV['CODEBOT_BIND'] unless ENV['CODEBOT_BIND'].to_s.empty?
    port = ENV['CODEBOT_PORT']
    if port.is_a?(String) && !port.empty?
      set :port, (server.valid! port, server.valid_port(port), nil,
                                invalid_error: 'invalid port %s')
    end
  end
end

Instance Method Details

#runObject

Starts this web server.



22
23
24
# File 'lib/codebot/web_server.rb', line 22

def run(*)
  create_server.run!
end