Class: Xapit::Server::App

Inherits:
Object
  • Object
show all
Defined in:
lib/xapit/server/app.rb

Instance Method Summary collapse

Instance Method Details

#action(command, json) ⇒ Object



14
15
16
17
# File 'lib/xapit/server/app.rb', line 14

def action(command, json)
  data = Xapit.symbolize_keys(JSON.parse(json))
  render :content => Xapit.database.send(command, data).to_json
end

#call(env) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/xapit/server/app.rb', line 4

def call(env)
  request = Rack::Request.new(env)
  command = request.path[%r</xapit/(.+)>, 1]
  if Database::COMMANDS.include? command
    action(command, request.body.gets)
  else
    render :status => 404
  end
end

#render(options = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/xapit/server/app.rb', line 19

def render(options = {})
  options[:status] ||= 200
  options[:content] ||= ""
  options[:content_type] ||= "text/html"
  [options[:status], {"Content-Type" => options[:content_type]}, [options[:content]]]
end