Class: Suggester::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/suggester/server.rb

Overview

Core server class

Constant Summary collapse

ACCEPTED_FORMATS =
['yml', 'json', 'html']

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Server

Create an instance of the server. At this time, we spawn a separate thread that will reload handlers as needed to prevent locking the server thread.



23
24
25
26
# File 'lib/suggester/server.rb', line 23

def initialize(*args)
  super(*args)
  spawn_refresh_thread!
end

Class Method Details

.add_handler(name, handler) ⇒ Object

Register a handler instance to its handler name



133
134
135
136
# File 'lib/suggester/server.rb', line 133

def self.add_handler(name, handler)
  @handlers ||= {}
  @handlers[name] = handler
end

.handler(name) ⇒ Object

Returns the handler instance given the handler name



127
128
129
130
# File 'lib/suggester/server.rb', line 127

def self.handler(name)
  @handlers ||= {}
  @handlers[name]
end

.handlersObject

Returns the hash of all handler names to their instances



122
123
124
# File 'lib/suggester/server.rb', line 122

def self.handlers
  @handlers
end