Skip to content
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
1 change: 1 addition & 0 deletions frameworks/Ruby/hanami/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "hanami-router", "~> 2.2"
gem "hanami-controller", "~> 2.2"
gem "hanami-db", "~> 2.2"
gem "hanami-validations", "~> 2.2"
gem "hanami-view", "~> 2.2"

gem "dry-types", "~> 1.0", ">= 1.6.1"
gem "puma"
Expand Down
10 changes: 10 additions & 0 deletions frameworks/Ruby/hanami/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ GEM
dry-transformer (~> 1.0, < 2)
hanami-validations (2.2.0)
dry-validation (>= 1.10, < 2)
hanami-view (2.2.1)
dry-configurable (~> 1.0)
dry-core (~> 1.0)
dry-inflector (~> 1.0, < 2)
temple (~> 0.10.0, >= 0.10.2)
tilt (~> 2.3)
zeitwerk (~> 2.6)
hansi (0.2.1)
ice_nine (0.11.2)
json (2.10.2)
Expand Down Expand Up @@ -146,6 +153,8 @@ GEM
ruby2_keywords (0.0.5)
sequel (5.90.0)
bigdecimal
temple (0.10.3)
tilt (2.6.0)
transproc (1.1.1)
zeitwerk (2.7.2)

Expand All @@ -160,6 +169,7 @@ DEPENDENCIES
hanami-db (~> 2.2)
hanami-router (~> 2.2)
hanami-validations (~> 2.2)
hanami-view (~> 2.2)
pg
puma
rake
Expand Down
12 changes: 12 additions & 0 deletions frameworks/Ruby/hanami/app/actions/fortunes/index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module HelloWorld
module Actions
module Fortunes
class Index < HelloWorld::Action
def handle(*, response)
end
end
end
end
end
7 changes: 7 additions & 0 deletions frameworks/Ruby/hanami/app/relations/fortunes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module HelloWorld
module Relations
class Fortunes < HelloWorld::DB::Relation
schema :Fortune, infer: true, as: :fortunes
end
end
end
11 changes: 11 additions & 0 deletions frameworks/Ruby/hanami/app/repos/fortune_repo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module HelloWorld
module Repos
class FortuneRepo < HelloWorld::DB::Repo
def all
results = fortunes.to_a.map(&:to_h)
results << { id: 0, message: 'Additional fortune added at request time.' }
results.sort_by! { |fortune| fortune[:message] }
end
end
end
end
12 changes: 12 additions & 0 deletions frameworks/Ruby/hanami/app/templates/fortunes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<table>
<tr>
<th>id</th>
<th>message</th>
</tr>
<% fortunes.each do |fortune| %>
<tr>
<td><%= fortune[:id] %></td>
<td><%= fortune[:message] %></td>
</tr>
<% end %>
</table>
6 changes: 2 additions & 4 deletions frameworks/Ruby/hanami/app/templates/layouts/app.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bookshelf</title>
<title>Fortunes</title>
</head>
<body>
<%= yield %>
Expand Down
14 changes: 14 additions & 0 deletions frameworks/Ruby/hanami/app/views/fortunes/index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module HelloWorld
module Views
module Fortunes
class Index < HelloWorld::View

include Deps["repos.fortune_repo"]

expose :fortunes do
fortune_repo.all
end
end
end
end
end
1 change: 1 addition & 0 deletions frameworks/Ruby/hanami/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"json_url": "/json",
"db_url": "/db",
"query_url": "/queries?queries=",
"fortune_url": "/fortunes",
"update_url": "/updates?queries=",
"plaintext_url": "/plaintext",
"port": 8080,
Expand Down
5 changes: 3 additions & 2 deletions frameworks/Ruby/hanami/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

module HelloWorld
class Routes < Hanami::Routes
get "/db", to: "db.index"
get "/json", to: "json.index"
get "/db", to: "db.index"
get "/queries", to: "queries.index"
get "/fortunes", to: "fortunes.index"
get "/updates", to: "updates.index"
get "/plaintext", to: "plaintext.index"
get "/queries", to: "queries.index"
end
end
Loading