From 9f222725d1a52f7fe2dde202466293bcf083a921 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Wed, 4 Sep 2024 15:23:53 -0500 Subject: [PATCH] Add json() helper --- app.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app.rb b/app.rb index c0fb7b0..3935d80 100644 --- a/app.rb +++ b/app.rb @@ -209,6 +209,16 @@ before do request.session_options[:skip] = !request.path_info.start_with?("/session") end +helpers do + def json(obj, opts: nil, pretty: false) + if pretty + JSON.pretty_generate obj, opts: + else + JSON.generate(obj, opts:) + end + end +end + get "/" do "hello there!\n" end