Add json() helper

This commit is contained in:
Ryan Cavicchioni 2024-09-04 15:23:53 -05:00
parent dfe9b1a90f
commit 9f222725d1
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D

10
app.rb
View File

@ -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