diff --git a/frameworks/Ruby/hanami/Gemfile b/frameworks/Ruby/hanami/Gemfile index d1d45e22f87..ebc633433f4 100644 --- a/frameworks/Ruby/hanami/Gemfile +++ b/frameworks/Ruby/hanami/Gemfile @@ -2,10 +2,11 @@ source "https://rubygems.org" -gem "hanami", "~> 2.0" -gem "hanami-router", "~> 2.0" -gem "hanami-controller", "~> 2.0" -gem "hanami-validations", "~> 2.0" +gem "hanami", "~> 2.2" +gem "hanami-router", "~> 2.2" +gem "hanami-controller", "~> 2.2" +gem "hanami-db", "~> 2.2" +gem "hanami-validations", "~> 2.2" gem "dry-types", "~> 1.0", ">= 1.6.1" gem "puma" diff --git a/frameworks/Ruby/hanami/Gemfile.lock b/frameworks/Ruby/hanami/Gemfile.lock index 36b859fb018..09111dda2dc 100644 --- a/frameworks/Ruby/hanami/Gemfile.lock +++ b/frameworks/Ruby/hanami/Gemfile.lock @@ -2,7 +2,7 @@ GEM remote: https://rubygems.org/ specs: bigdecimal (3.1.9) - concurrent-ruby (1.3.4) + concurrent-ruby (1.3.5) dry-auto_inject (1.1.0) dry-core (~> 1.1) zeitwerk (~> 2.6) @@ -30,38 +30,38 @@ GEM dry-configurable (~> 1.0, < 2) dry-core (~> 1.0, < 2) dry-events (~> 1.0, < 2) - dry-schema (1.13.4) + dry-schema (1.14.1) concurrent-ruby (~> 1.0) dry-configurable (~> 1.0, >= 1.0.1) - dry-core (~> 1.0, < 2) - dry-initializer (~> 3.0) - dry-logic (>= 1.4, < 2) - dry-types (>= 1.7, < 2) - zeitwerk (~> 2.6) - dry-struct (1.7.0) dry-core (~> 1.1) + dry-initializer (~> 3.2) + dry-logic (~> 1.5) dry-types (~> 1.8) + zeitwerk (~> 2.6) + dry-struct (1.8.0) + dry-core (~> 1.1) + dry-types (~> 1.8, >= 1.8.2) ice_nine (~> 0.11) zeitwerk (~> 2.6) - dry-system (1.2.0) + dry-system (1.2.2) dry-auto_inject (~> 1.1) dry-configurable (~> 1.3) dry-core (~> 1.1) dry-inflector (~> 1.1) dry-transformer (1.0.1) zeitwerk (~> 2.6) - dry-types (1.8.0) + dry-types (1.8.2) bigdecimal (~> 3.0) concurrent-ruby (~> 1.0) dry-core (~> 1.0) dry-inflector (~> 1.0) dry-logic (~> 1.4) zeitwerk (~> 2.6) - dry-validation (1.10.0) + dry-validation (1.11.1) concurrent-ruby (~> 1.0) - dry-core (~> 1.0, < 2) - dry-initializer (~> 3.0) - dry-schema (>= 1.12, < 2) + dry-core (~> 1.1) + dry-initializer (~> 3.2) + dry-schema (~> 1.14) zeitwerk (~> 2.6) hanami (2.2.1) bundler (>= 1.16, < 3) @@ -82,13 +82,17 @@ GEM dry-inflector (~> 1.0, < 2) rake (~> 13.0) zeitwerk (~> 2.6) - hanami-controller (2.1.0) + hanami-controller (2.2.0) dry-configurable (~> 1.0, < 2) dry-core (~> 1.0) - hanami-utils (~> 2.1) + hanami-utils (~> 2.2) rack (~> 2.0) zeitwerk (~> 2.6) - hanami-router (2.1.0) + hanami-db (2.2.1) + rom (~> 5.4, >= 5.4.1) + rom-sql (~> 3.7) + zeitwerk (~> 2.6) + hanami-router (2.2.0) mustermann (~> 3.0) mustermann-contrib (~> 3.0) rack (~> 2.0) @@ -96,13 +100,12 @@ GEM concurrent-ruby (~> 1.0) dry-core (~> 1.0, < 2) dry-transformer (~> 1.0, < 2) - hanami-validations (2.1.0) + hanami-validations (2.2.0) dry-validation (>= 1.10, < 2) - zeitwerk (~> 2.6.0) hansi (0.2.1) ice_nine (0.11.2) - json (2.9.1) - logger (1.6.4) + json (2.10.2) + logger (1.6.6) mustermann (3.0.3) ruby2_keywords (~> 0.0.1) mustermann-contrib (3.0.3) @@ -110,41 +113,41 @@ GEM mustermann (= 3.0.3) nio4r (2.7.4) pg (1.5.9) - puma (6.5.0) + puma (6.6.0) nio4r (~> 2.0) - rack (2.2.9) + rack (2.2.13) rake (13.2.1) - rom (5.3.2) - rom-changeset (~> 5.3, >= 5.3.0) - rom-core (~> 5.3, >= 5.3.2) - rom-repository (~> 5.3, >= 5.3.0) - rom-changeset (5.3.0) + rom (5.4.2) + rom-changeset (~> 5.4) + rom-core (~> 5.4) + rom-repository (~> 5.4, >= 5.4.2) + rom-changeset (5.4.0) dry-core (~> 1.0) - rom-core (~> 5.3) - transproc (~> 1.0, >= 1.1.0) - rom-core (5.3.2) + rom-core (~> 5.4) + transproc (~> 1.1) + rom-core (5.4.0) concurrent-ruby (~> 1.1) dry-configurable (~> 1.0) dry-core (~> 1.0) dry-inflector (~> 1.0) - dry-initializer (~> 3.0, >= 3.0.1) + dry-initializer (~> 3.2) dry-struct (~> 1.0) dry-types (~> 1.6) - transproc (~> 1.0, >= 1.1.0) - rom-repository (5.3.0) - dry-core (~> 1.0) - dry-initializer (~> 3.0, >= 3.0.1) - rom-core (~> 5.3, >= 5.3.0) - rom-sql (3.6.5) + transproc (~> 1.1) + rom-repository (5.4.2) dry-core (~> 1.0) - dry-types (~> 1.0) - rom (~> 5.2, >= 5.2.1) + dry-initializer (~> 3.2) + rom-core (~> 5.4) + rom-sql (3.7.0) + dry-core (~> 1.1) + dry-types (~> 1.8) + rom (~> 5.4) sequel (>= 4.49) ruby2_keywords (0.0.5) - sequel (5.88.0) + sequel (5.90.0) bigdecimal transproc (1.1.1) - zeitwerk (2.6.18) + zeitwerk (2.7.2) PLATFORMS ruby @@ -152,10 +155,11 @@ PLATFORMS DEPENDENCIES dry-types (~> 1.0, >= 1.6.1) - hanami (~> 2.0) - hanami-controller (~> 2.0) - hanami-router (~> 2.0) - hanami-validations (~> 2.0) + hanami (~> 2.2) + hanami-controller (~> 2.2) + hanami-db (~> 2.2) + hanami-router (~> 2.2) + hanami-validations (~> 2.2) pg puma rake diff --git a/frameworks/Ruby/hanami/Procfile.dev b/frameworks/Ruby/hanami/Procfile.dev new file mode 100644 index 00000000000..04e92a10dc1 --- /dev/null +++ b/frameworks/Ruby/hanami/Procfile.dev @@ -0,0 +1,2 @@ +web: bundle exec hanami server +# assets: bundle exec hanami assets watch diff --git a/frameworks/Ruby/hanami/app/action.rb b/frameworks/Ruby/hanami/app/action.rb index 0771adb9298..8ef93e34f4a 100644 --- a/frameworks/Ruby/hanami/app/action.rb +++ b/frameworks/Ruby/hanami/app/action.rb @@ -5,5 +5,13 @@ module HelloWorld class Action < Hanami::Action + before :set_headers + + private + + def set_headers(*, response) + response.headers['Server'] = 'hanami' + response.headers['Date'] = Time.now.httpdate + end end end diff --git a/frameworks/Ruby/hanami/app/actions/db/index.rb b/frameworks/Ruby/hanami/app/actions/db/index.rb index 98b8ed970d8..e5efcc2f414 100644 --- a/frameworks/Ruby/hanami/app/actions/db/index.rb +++ b/frameworks/Ruby/hanami/app/actions/db/index.rb @@ -5,14 +5,13 @@ module Actions module DB class Index < HelloWorld::Action QUERY_RANGE = 1..10_000 # range of IDs in the Fortune DB - include Deps["persistence.rom"] + + include Deps["repos.world_repo"] def handle(*, response) - world = rom.relations[:World].by_pk(random_id).one - response.headers['Server'] = 'hanami' - response.headers['Date'] = Time.now.httpdate + world = world_repo.find(random_id) response.format = :json - response.body = world.to_json + response.body = world.to_h.to_json end def random_id diff --git a/frameworks/Ruby/hanami/app/actions/json/index.rb b/frameworks/Ruby/hanami/app/actions/json/index.rb index a49b641cb7c..9dd7220a45c 100644 --- a/frameworks/Ruby/hanami/app/actions/json/index.rb +++ b/frameworks/Ruby/hanami/app/actions/json/index.rb @@ -5,8 +5,6 @@ module Actions module JSON class Index < HelloWorld::Action def handle(*, response) - response.headers['Server'] = 'hanami' - response.headers['Date'] = Time.now.httpdate response.format = :json response.body = { 'message' => 'Hello, World!' }.to_json end diff --git a/frameworks/Ruby/hanami/app/actions/plaintext/index.rb b/frameworks/Ruby/hanami/app/actions/plaintext/index.rb index 62523769a66..dee41365b02 100644 --- a/frameworks/Ruby/hanami/app/actions/plaintext/index.rb +++ b/frameworks/Ruby/hanami/app/actions/plaintext/index.rb @@ -5,8 +5,6 @@ module Actions module Plaintext class Index < HelloWorld::Action def handle(*, response) - response.headers['Server'] = 'hanami' - response.headers['Date'] = Time.now.httpdate response.body = 'Hello, World!' end end diff --git a/frameworks/Ruby/hanami/app/actions/queries/index.rb b/frameworks/Ruby/hanami/app/actions/queries/index.rb index 5a1d0bd1419..d20dfc2df3a 100644 --- a/frameworks/Ruby/hanami/app/actions/queries/index.rb +++ b/frameworks/Ruby/hanami/app/actions/queries/index.rb @@ -9,16 +9,14 @@ class Index < HelloWorld::Action MIN_QUERIES = 1 # min number of records that can be retrieved MAX_QUERIES = 500 # max number of records that can be retrieved - include Deps["persistence.rom"] + include Deps["repos.world_repo"] def handle(request, response) worlds = ALL_IDS.sample(queries(request)).map do |id| - rom.relations[:World].by_pk(id).one + world_repo.find(id) end - response.headers['Server'] = 'hanami' - response.headers['Date'] = Time.now.httpdate response.format = :json - response.body = worlds.to_json + response.body = worlds.map(&:to_h).to_json end private diff --git a/frameworks/Ruby/hanami/app/actions/updates/index.rb b/frameworks/Ruby/hanami/app/actions/updates/index.rb index 54f963f7bf2..88c85a2ff60 100644 --- a/frameworks/Ruby/hanami/app/actions/updates/index.rb +++ b/frameworks/Ruby/hanami/app/actions/updates/index.rb @@ -9,20 +9,12 @@ class Index < HelloWorld::Action MIN_QUERIES = 1 # min number of records that can be retrieved MAX_QUERIES = 500 # max number of records that can be retrieved - include Deps["persistence.rom"] + include Deps["repos.world_repo"] def handle(request, response) worlds = ALL_IDS.sample(queries(request)).map do |id| - world = rom.relations[:World].by_pk(id) - world_struct = world.one - new_value = random_id - new_value = random_id while new_value == world_struct[:randomnumber] - world_struct[:randomnumber] = new_value - world.command(:update).call(randomnumber: world_struct[:randomnumber]) - world_struct + world_repo.update(id) end - response.headers['Server'] = 'hanami' - response.headers['Date'] = Time.now.httpdate response.format = :json response.body = worlds.to_json end diff --git a/frameworks/Ruby/hanami/app/db/relation.rb b/frameworks/Ruby/hanami/app/db/relation.rb new file mode 100644 index 00000000000..9ff3c56789f --- /dev/null +++ b/frameworks/Ruby/hanami/app/db/relation.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require "hanami/db/relation" + +module HelloWorld + module DB + class Relation < Hanami::DB::Relation + end + end +end diff --git a/frameworks/Ruby/hanami/app/db/repo.rb b/frameworks/Ruby/hanami/app/db/repo.rb new file mode 100644 index 00000000000..586c7af94d0 --- /dev/null +++ b/frameworks/Ruby/hanami/app/db/repo.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require "hanami/db/repo" + +module HelloWorld + module DB + class Repo < Hanami::DB::Repo + end + end +end diff --git a/frameworks/Ruby/hanami/app/db/struct.rb b/frameworks/Ruby/hanami/app/db/struct.rb new file mode 100644 index 00000000000..5484ea7c357 --- /dev/null +++ b/frameworks/Ruby/hanami/app/db/struct.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require "hanami/db/struct" + +module HelloWorld + module DB + class Struct < Hanami::DB::Struct + end + end +end diff --git a/frameworks/Ruby/hanami/app/relations/.keep b/frameworks/Ruby/hanami/app/relations/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/frameworks/Ruby/hanami/app/relations/worlds.rb b/frameworks/Ruby/hanami/app/relations/worlds.rb new file mode 100644 index 00000000000..54d982fa9bf --- /dev/null +++ b/frameworks/Ruby/hanami/app/relations/worlds.rb @@ -0,0 +1,7 @@ +module HelloWorld + module Relations + class Worlds < HelloWorld::DB::Relation + schema :World, infer: true, as: :worlds + end + end +end diff --git a/frameworks/Ruby/hanami/app/repos/.keep b/frameworks/Ruby/hanami/app/repos/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/frameworks/Ruby/hanami/app/repos/world_repo.rb b/frameworks/Ruby/hanami/app/repos/world_repo.rb new file mode 100644 index 00000000000..40baa32c089 --- /dev/null +++ b/frameworks/Ruby/hanami/app/repos/world_repo.rb @@ -0,0 +1,27 @@ +module HelloWorld + module Repos + class WorldRepo < HelloWorld::DB::Repo + QUERY_RANGE = 1..10_000 # range of IDs in the Fortune DB + + def find(id) + worlds.by_pk(id).one + end + + def update(id) + world = worlds.by_pk(id) + world_hash = world.one.to_h + new_value = random_id + new_value = random_id while new_value == world_hash[:randomnumber] + world_hash[:randomnumber] = new_value + world.changeset(:update, **world_hash).commit + world_hash + end + + private + + def random_id + Random.rand(QUERY_RANGE) + end + end + end +end diff --git a/frameworks/Ruby/hanami/app/structs/.keep b/frameworks/Ruby/hanami/app/structs/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/frameworks/Ruby/hanami/app/templates/layouts/app.html.erb b/frameworks/Ruby/hanami/app/templates/layouts/app.html.erb new file mode 100644 index 00000000000..ab87e9112bd --- /dev/null +++ b/frameworks/Ruby/hanami/app/templates/layouts/app.html.erb @@ -0,0 +1,11 @@ + + +
+ + +