Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frameworks/Ruby/hanami/app/actions/db/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Index < HelloWorld::Action
def handle(*, response)
world = world_repo.find(random_id)
response.format = :json
response.body = world.to_h.to_json
response.body = JSON.generate(world.to_h)
end

def random_id
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Ruby/hanami/app/actions/queries/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def handle(request, response)
world_repo.find(id)
end
response.format = :json
response.body = worlds.map(&:to_h).to_json
response.body = JSON.generate(worlds.map(&:to_h))
end

private
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Ruby/hanami/app/actions/updates/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def handle(request, response)
world_repo.update_random_number(id)
end
response.format = :json
response.body = worlds.to_json
response.body = JSON.generate(worlds)
end

private
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Ruby/hanami/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Routes < Hanami::Routes
'Content-Type' => 'application/json',
'Date' => Time.now.httpdate,
},
[{ 'message' => 'Hello, World!' }.to_json]]
[JSON.generate({ 'message' => 'Hello, World!' })]]
end
get "/db", to: "db.index"
get "/queries", to: "queries.index"
Expand Down
8 changes: 4 additions & 4 deletions frameworks/Ruby/padrino/app/controllers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
end

get '/json', :provides => [:json] do
{message: "Hello, World!"}.to_json
JSON.generate({message: "Hello, World!"})
end

get '/db', :provides => [:json] do
world = ActiveRecord::Base.with_connection do
World.find(rand1).attributes
end
world.to_json
JSON.generate(world)
end

get '/queries', :provides => [:json] do
Expand All @@ -24,7 +24,7 @@
World.find(id).attributes
end
end
worlds.to_json
JSON.generate(worlds)
end

get '/fortunes' do
Expand All @@ -51,7 +51,7 @@
World.upsert_all(worlds)
end

worlds.to_json
JSON.generate(worlds)
end

get '/plaintext' do
Expand Down
9 changes: 5 additions & 4 deletions frameworks/Ruby/rack-app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,23 @@ def fortunes

get '/json' do
set_headers(JSON_TYPE)
{ message: 'Hello, World!' }.to_json
JSON.generate({ message: 'Hello, World!' })
end

get '/db' do
set_headers(JSON_TYPE)
World.with_pk(rand1).values.to_json
JSON.generate(World.with_pk(rand1).values)
end

get '/queries' do
set_headers(JSON_TYPE)
ids = ALL_IDS.sample(bounded_queries)
DB.synchronize do
worlds = DB.synchronize do
ids.map do |id|
World.with_pk(id).values
end
end.to_json
end
JSON.generate(worlds)
end

get '/fortunes' do
Expand Down
8 changes: 4 additions & 4 deletions frameworks/Ruby/rack-sequel/hello_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ def call(env)
case env['PATH_INFO']
when '/json'
# Test type 1: JSON serialization
respond JSON_TYPE, { message: 'Hello, World!' }.to_json
respond JSON_TYPE, JSON.generate({ message: 'Hello, World!' })
when '/db'
# Test type 2: Single database query
respond JSON_TYPE, db.to_json
respond JSON_TYPE, JSON.generate(db)
when '/queries'
# Test type 3: Multiple database queries
respond JSON_TYPE, queries(env).to_json
respond JSON_TYPE, JSON.generate(queries(env))
when '/fortunes'
# Test type 4: Fortunes
respond HTML_TYPE, fortunes
when '/updates'
# Test type 5: Database updates
respond JSON_TYPE, updates(env).to_json
respond JSON_TYPE, JSON.generate(updates(env))
when '/plaintext'
# Test type 6: Plaintext
respond PLAINTEXT_TYPE, 'Hello, World!'
Expand Down
8 changes: 4 additions & 4 deletions frameworks/Ruby/rack/hello_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ def call(env)
when '/json'
# Test type 1: JSON serialization
respond JSON_TYPE,
{ message: 'Hello, World!' }.to_json
JSON.generate({ message: 'Hello, World!' })
when '/db'
# Test type 2: Single database query
id = random_id
respond JSON_TYPE, $db.with{ _1.select_world(id) }.to_json
respond JSON_TYPE, JSON.generate($db.with{ _1.select_world(id) })
when '/queries'
# Test type 3: Multiple database queries
queries = bounded_queries(env)
respond JSON_TYPE, select_worlds(queries).to_json
respond JSON_TYPE, JSON.generate(select_worlds(queries))
when '/fortunes'
# Test type 4: Fortunes
respond HTML_TYPE, fortunes
when '/updates'
# Test type 5: Database updates
queries = bounded_queries(env)
respond JSON_TYPE, update_worlds(queries).to_json
respond JSON_TYPE, JSON.generate(update_worlds(queries))
when '/plaintext'
# Test type 6: Plaintext
respond PLAINTEXT_TYPE, 'Hello, World!'
Expand Down
4 changes: 2 additions & 2 deletions frameworks/Ruby/rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'Content-Type' => 'application/json',
'Date' => Time.now.httpdate,
},
[{ 'message' => 'Hello, World!' }.to_json]]
[JSON.generate({ 'message' => 'Hello, World!' })]]
end
else
->(env) do
Expand All @@ -18,7 +18,7 @@
'Server' => 'Rails',
'Content-Type' => 'application/json'
},
[{ 'message' => 'Hello, World!' }.to_json]]
[JSON.generate({ 'message' => 'Hello, World!' })]]
end
end

Expand Down
8 changes: 4 additions & 4 deletions frameworks/Ruby/roda-sequel/hello_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ def rand1
# Test type 1: JSON serialization
r.is "json" do
response[CONTENT_TYPE] = JSON_TYPE
{ message: "Hello, World!" }.to_json
JSON.generate({ message: "Hello, World!" })
end

# Test type 2: Single database query
r.is "db" do
response[CONTENT_TYPE] = JSON_TYPE
World.with_pk(rand1).values.to_json
JSON.generate(World.with_pk(rand1).values)
end

# Test type 3: Multiple database queries
Expand All @@ -60,7 +60,7 @@ def rand1
World.with_pk(id).values
end
end
worlds.to_json
JSON.generate(worlds)
end

# Test type 4: Fortunes
Expand Down Expand Up @@ -93,7 +93,7 @@ def rand1
end
World.batch_update(worlds)
end
worlds.map!(&:values).to_json
JSON.generate(worlds.map!(&:values))
end

# Test type 6: Plaintext
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Ruby/sinatra-sequel/hello_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class HelloWorld < Sinatra::Base
def render_json(data)
add_headers
content_type :json
data.to_json
JSON.generate(data)
end

def render_html(template)
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Ruby/sinatra/hello_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class HelloWorld < Sinatra::Base
def render_json(data)
add_headers
content_type :json
data.to_json
JSON.generate(data)
end

def render_html(template)
Expand Down
Loading