From ddeb5731aacb3632f5ce2ab14cf0cfee70bc09eb Mon Sep 17 00:00:00 2001 From: Andy Brown Date: Mon, 3 Aug 2015 17:26:20 +0100 Subject: [PATCH] format ruby --- server.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/server.rb b/server.rb index 6bfb84a1..5f20ca70 100644 --- a/server.rb +++ b/server.rb @@ -19,22 +19,22 @@ server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => root server.mount_proc '/comments.json' do |req, res| - comments = JSON.parse(File.read('./comments.json')) - - if req.request_method == 'POST' - # Assume it's well formed - comment = {} - req.query.each do |key, value| - comment[key] = value.force_encoding('UTF-8') + comments = JSON.parse(File.read('./comments.json')) + + if req.request_method == 'POST' + # Assume it's well formed + comment = {} + req.query.each do |key, value| + comment[key] = value.force_encoding('UTF-8') + end + comments << comment + File.write('./comments.json', JSON.pretty_generate(comments, :indent => ' ')) end - comments << comment - File.write('./comments.json', JSON.pretty_generate(comments, :indent => ' ')) - end - - # always return json - res['Content-Type'] = 'application/json' - res['Cache-Control'] = 'no-cache' - res.body = JSON.generate(comments) + + # always return json + res['Content-Type'] = 'application/json' + res['Cache-Control'] = 'no-cache' + res.body = JSON.generate(comments) end trap 'INT' do server.shutdown end