class Adminix::Web::Server

Public Instance Methods

http_request_errback(e) click to toggle source
# File lib/adminix/web/server.rb, line 19
def http_request_errback(e)
  # printing the whole exception
  puts e.inspect
end
not_found_route() click to toggle source

Routes

# File lib/adminix/web/server.rb, line 26
def not_found_route
  content = 'Page not found'
  render text: content, status: 404
end
process_http_request() click to toggle source
# File lib/adminix/web/server.rb, line 6
def process_http_request
  # puts  @http_request_method
  # puts  @http_request_uri
  # puts  @http_query_string
  # puts  @http_protocol
  # puts  @http_content
  # puts  @http[:cookie]
  # puts  @http[:content_type]
  # you have all the http headers in this hash
  # puts  @http.inspect
  process_request
end

Private Instance Methods

construct_response(content, opts = {}) click to toggle source
# File lib/adminix/web/server.rb, line 47
def construct_response(content, opts = {})
  res = EM::DelegatedHttpResponse.new(self)
  res.status = opts[:status] || 200
  res.content_type opts[:content_type] || 'text/plain'
  res.content = content
  res
end
render(opts) click to toggle source

Helpers

# File lib/adminix/web/server.rb, line 35
def render(opts)
  res = if opts[:html]
          construct_response(opts[:html], content_type: 'text/html')
        elsif opts[:text]
          construct_response(opts[:text])
        elsif opts[:json]
          construct_response(opts[:json], content_type: 'application/json')
        end

  res.send_response
end
view(path) click to toggle source
# File lib/adminix/web/server.rb, line 55
def view(path)
  Helpers::Files.read_erb_tpl(path, binding)
end