class Suggester::Server
Core server class
Constants
- ACCEPTED_FORMATS
Public Class Methods
add_handler(name, handler)
click to toggle source
Register a handler instance to its handler name
# File lib/suggester/server.rb, line 133 def self.add_handler(name, handler) @handlers ||= {} @handlers[name] = handler end
handler(name)
click to toggle source
Returns the handler instance given the handler name
# File lib/suggester/server.rb, line 127 def self.handler(name) @handlers ||= {} @handlers[name] end
handlers()
click to toggle source
Returns the hash of all handler names to their instances
# File lib/suggester/server.rb, line 122 def self.handlers @handlers end
new(*args)
click to toggle source
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.
Calls superclass method
# File lib/suggester/server.rb, line 23 def initialize(*args) super(*args) spawn_refresh_thread! end
Private Instance Methods
invalid_format(message = "Invalid Format")
click to toggle source
# File lib/suggester/server.rb, line 163 def invalid_format(message = "Invalid Format") [ 404, {'Content-Type' => 'text/plain'}, message ] end
parse_format_and_query_from_splat(params)
click to toggle source
# File lib/suggester/server.rb, line 140 def parse_format_and_query_from_splat(params) # get the splat param(s) - Array of arrays. splat = params.delete("splat") return nil, nil unless splat.kind_of?(Array) # were only expecting one splat, get the first one and split it on period splat = splat.first.split(".") # format is the last token format = splat.pop # If format isn't acceptable, push it back onto splat and set format to nil unless ACCEPTED_FORMATS.include?(format) splat.push(format) format = nil end # join the array of of splat as query query = splat.join(".") # return format and query return format, query end