timriley on add-equalizer-to-callback-chain
timriley on main
Make chains comparable via #== … (compare)
timriley on add-equalizer-to-callback-chain
Update CHANGELOG (compare)
timriley on 2.0.x
Update CHANGELOG for v2.0.0 (#1… (compare)
depfu[bot] on update
jodosha on main
Update hanami-utils to version … (compare)
Hi Bilel. If you're taking about hanami-api, that will likely be deprecated soon. The reason is that, the full hanami framework will allow you to load only the components you need. And, you can always use hanami-router directly, if you're looking for a minimal API (though, with entities and actions, it seems like you'll want to use the full hanami framework).
If you install
gem install hanami --pre then run
hanami version to ensure you have v2.0.0.beta2, you can use
hanami new to create a new app. FYI though, you'll be on your own for entities for now, and we recommend using ROM 5. Hanami 2.0 won't have a model layer, but Hanami 2.1 will (and will use ROM 6, which isn't out yet)
Hey @/all ,
I had achieved a long-awaited milestone of starting a premium version of Hanami Mastery, to make the first step to sustainability, and ensure this initiative won’t fade away, but rather stay here to promote Hanami long term.
If you’d like to help me a bit, I’d appreciate it if you could fill out this very short feedback form:
If you’ll hit the checkbox at the top and fill in the twitter handle, I’ll share your feedback with the world :)
Hello, I'm trying Hanami 2 and I can't find a way to configure background jobs using Que. All it needs a Sequel database connection. My first though be using an initializers but it does not seem to exist in Hanami 2. Should I use a provider?
I followed @swilgosz guide to configure the persistence using ROM. What I would like to do is
require 'que' Que.connection = HomeBar::Container['persistence.db']
This way I can enqueue job like this.
Jobs are defined like this:
class MyJob < Que::Job def run; end end
Disclaimer I'm new to dry-system and dry-container.
Does someone have a hint for me?
/usr/local/bundle/gems/dry-system-0.27.2/lib/dry/system/container.rb:57:in<class:Container>': uninitialized constant Dry::System::Plugins (NameError)` when testing the latest beta in https://github.com/the-benchmarker/web-frameworks/tree/master/ruby/hanami
paramsblock within the action and using standalone hanami-validations objects ?or maybe i should go directly with dry-validations ?
user_id, but would like to pass
admin_user_idto repository). where would you place such logic ? should that be within scope of responsibility of validations/coercions or rather separate step within action before calling repo ?
@/all Hanami v2.0.0.rc1
bundle exec hanami --help? or is it specific to each ruby setup ? (rbenv here)
Bundler could not find compatible versions for gem "dry-core": In Gemfile: hanami (~> 2.0.0.rc) was resolved to 2.0.0.rc1, which depends on dry-core (~> 1.0, < 2) rom (~> 5.2) was resolved to 5.2.6, which depends on rom-repository (>= 5.2.2, ~> 5.2) was resolved to 5.2.2, which depends on dry-core (~> 0.4) rom-sql (~> 3.5) was resolved to 3.5.0, which depends on dry-core (>= 0.5, ~> 0.5) Bundler could not find compatible versions for gem "hanami": In Gemfile: hanami (~> 2.0.0.rc) hanami-reloader was resolved to 0.2.1, which depends on hanami (~> 1.1)
I started exploring Hanami and as part of that started following the 2.0 guide at https://guides.hanamirb.org/v2.0/introduction/getting-started.
I am trying to access a relation class in console but am getting
NameError: uninitialized constant related to
Please find relevant code snippets below:
# config/providers/persistence.rb Hanami.app.register_provider :persistence, namespace: true do prepare do require 'rom/core' require 'rom/sql' #require 'rom-repository' @config = ROM::Configuration.new(:sql, target["settings"].database_url) register "config", @config register "db", @config.gateways[:default].connection end start do @config.auto_registration( target.root.join('lib/startup_template/persistence'), namespace: 'StartupTemplate::Persistence' ) register "rom", ROM.container(@config) end end
# lib/startup_template/persistence/relations/doctors.rb module StartupTemplate module Persistence module Relations class Doctors < ROM::Relation[:sql] schema(:doctors, infer: true) end end end end
$HANAMI_ENV=test bundle exec hanami console startup_template[test]> StartupTemplate::Persistence::Relations::Doctors NameError: uninitialized constant StartupTemplate::Persistence::Relations::ROM class Doctors < ROM::Relation[:sql] ^^^ from /....../startup_template/lib/startup_template/persistence/relations/doctors.rb:6:in `<module:Relations>'
class Doctors < ::ROM::Relation[:sql]but no luck
Few more things I have to ask are:
I Initially explored 1.3 guide to get a basic understanding of the Hanami concepts. Then navigated to 2.0 guide but looks like there is a radical change between concepts in both the versions. For e.g. trying to generate model for my
Doctor concept in my 2.0 application using the documentation from 1.3 I couldn't generate it.
2.0 guide demonstrates building a JSON API. I want to prototype a web application rendering HAML views but in the guide Views concept is not demonstrated.
As a beginner to Hanami, following the 2.0 guide I am unable the understand conventions for organizing code which is clear looking at 1.3 guide.
For accessing relations using a repository following hint is given in the guide
Accessing relations directly from actions is not a commonly recommended pattern. Instead, a rom repository should be used. Here, however, the repository is ommitted for brevity. Hanami's 2.1 release will offer repositories out of the box.
For one like me who want to utilize repositories in an application based on 2.0 version it is difficult to follow along with no example available on how to utilize repositories.
I have a question about hanami v2.
When I trying to write code using hanami v2, I can't find how to share before callback which exists in hanami v1 as "controller.prepare".
How can I do such a thing?
I want to introduce ROM Repositories in a Hanami 2.0 based web app prototype I am trying to build.
Based on my understanding of Repositories concept while going through
https://rom-rb.org/5.0/learn/getting-started/core-concepts/ (ROM architecture diagram)
till now I have come up with following:
# structure of application app actions action.rb config providers persistence.rb lib startup_template persistence relations doctors.rb slices admin actions action.rb repositories doctor_repository.rb
# startup_template/config/providers/persistence.rb Hanami.app.register_provider :persistence, namespace: true do prepare do require 'rom/core' require 'rom/sql' #require 'rom-repository' @config = ROM::Configuration.new(:sql, target["settings"].database_url) register "config", @config register "db", @config.gateways[:default].connection end start do @config.auto_registration( target.root.join('lib/startup_template/persistence'), namespace: 'StartupTemplate::Persistence' ) register "rom", ROM.container(@config) end end
# startup_template/lib/startup_template/persistence/relations/doctors.rb module StartupTemplate module Persistence module Relations class Doctors < ROM::Relation[:sql] schema(:doctors, infer: true) end end end end
# startup_template/slices/admin/repositories/doctor_repository.rb module Admin module Repositories class DoctorRepository < ROM::Repository[:doctors] commands :create, update: :by_pk, delete: :by_pk end end end
Now I am stuck with a question that how can I avoid
require 'rom-repository' in all my repository classes? Is it possible? Following the providers demonstration given at https://guides.hanamirb.org/v2.0/introduction/getting-started/#persisting-books,
one approach which I could think of is like following:
# startup_template/slices/admin/providers/repository.rb Hanami.app.register_provider :repository, namespace: true do prepare do require 'rom-repository' @config = target["config"] end start do @config.auto_registration( target.root.join('lib/repositories'), namespace: 'Admin::Repositories' ) end end
but I don't think it should work for following reasons:
ROM config is ultimately given to
ROM.container(@config) and that is already done by
startup_template/config/providers/persistence.rb. In such a case I don't think above approach should work.
auto_registration doesn't allow registering multiple paths (atleast
from documentation at https://api.rom-rb.org/rom/ROM/Setup.html#auto_registration-instance_method my understanding is that).
Can anybody please share their views on above and guide me whether I am on right path or not? And please rectify me if I am wrong at any place. I am beginner to Hanami and ROM. So please bear with me on anything you find not correct.
I have a question about hanami v2.
hanami/interactor now with hanami v1, but I found
hanami/interactor was removed from hanami v2.
Does Anyone know why
hanami/interactor was removed?
And how we should change the old interactor? (For example we think we'll change
error! method to
raise. Is it the right way in hanami v2? ref: https://docs.hanamirb.org/1.3.3/hanami/interactor)
@/all Hanami 2.0.0 is finally here! <3
Hi guys, I was trying Hanami 2.0 and faced an issue with the dev server port configuration. This is a new project, with no modifications after running
hanami new bookshelf.
$ bundle exec hanami version v2.0.0
$ HANAMI_PORT=5000 bundle exec hanami server 17:39:02 - INFO - Using Guardfile at /bookshelf/Guardfile. 17:39:02 - INFO - Puma starting on port 2300 in development environment. 17:39:02 - INFO - Guard is now watching at '/bookshelf'  Puma starting in cluster mode...  * Puma version: 6.0.0 (ruby 3.1.2-p20) ("Sunflower")  * Min threads: 5  * Max threads: 5  * Environment: development  * Master PID: 1392505  * Workers: 2  * Restarts: (✔) hot (✖) phased  * Preloading application  * Listening on http://0.0.0.0:2300
$ HANAMI_PORT=5000 bundle exec puma -C config/puma.rb  Puma starting in cluster mode...  * Puma version: 6.0.0 (ruby 3.1.2-p20) ("Sunflower")  * Min threads: 5  * Max threads: 5  * Environment: development  * Master PID: 1392728  * Workers: 2  * Restarts: (✔) hot (✖) phased  * Preloading application  * Listening on http://0.0.0.0:5000
For some reason
hanami server doesn't react to changes in env variables or changes to the
.env file. While with
puma it's working as expected.
I am trying to add
Rack::Static middleware to my Hanami 2.0 app but am encountering error while starting server.
# config/app.rb # frozen_string_literal: true require "hanami" module StartupTemplate class App < Hanami::App config.middleware.use Rack::Static, urls: ["/css", "/images"], root: "public" end end
 Puma starting in cluster mode...  * Puma version: 6.0.0 (ruby 3.1.2-p20) ("Sunflower")  * Min threads: 5  * Max threads: 5  * Environment: development  * Master PID: 10080  * Workers: 2  * Restarts: (✔) hot (✖) phased  * Preloading application  ! Unable to load application: ArgumentError: unknown keywords: :urls, :root /home/jignesh/.rvm/gems/ruby-3.1.2@startup-template-hanami-2-0/gems/hanami-2.0.0/lib/hanami/slice/routing/middleware/stack.rb:94:in `use': unknown keywords: :urls, :root (ArgumentError) from /..../startup_template/config/app.rb:7:in `<class:App>' from /..../startup_template/config/app.rb:6:in `<module:StartupTemplate>' from /..../startup_template/config/app.rb:5:in `<top (required)>' from /home/jignesh/.rvm/gems/ruby-3.1.2@startup-template-hanami-2-0/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require' from /home/jignesh/.rvm/gems/ruby-3.1.2@startup-template-hanami-2-0/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require' from /home/jignesh/.rvm/gems/ruby-3.1.2@startup-template-hanami-2-0/gems/hanami-2.0.0/lib/hanami.rb:41:in `setup' from /home/jignesh/.rvm/gems/ruby-3.1.2@startup-template-hanami-2-0/gems/hanami-2.0.0/lib/hanami/setup.rb:6:in `<top (required)>' from /home/jignesh/.rvm/gems/ruby-3.1.2@startup-template-hanami-2-0/gems/hanami-2.0.0/lib/hanami/boot.rb:3:in `require_relative' from /home/jignesh/.rvm/gems/ruby-3.1.2@startup-template-hanami-2-0/gems/hanami-2.0.0/lib/hanami/boot.rb:3:in `<top (required)>' from config.ru:3:in `require' from config.ru:3:in `block in <main>'
Checking the source code https://github.com/hanami/hanami/blob/beb60078bc9a5e84ba77946f2823ee12f7f6d0dc/lib/hanami/slice/routing/middleware/stack.rb#L94 the
*args is expected to be an optional Array. And the specs at https://github.com/hanami/hanami/blob/beb60078bc9a5e84ba77946f2823ee12f7f6d0dc/spec/integration/rack_app/middleware_spec.rb doesn't illustrate any middleware accepting keyword args as middleware's option. So is it that Hanami doesn't support middlewares accepting keyword args?
Hi! Congratulations to everyone on the 2.0 release, I've been waiting for it for a very long time!
I decided to test Hanami 2.0 and did everything according to the documentation from A to Z. I reached the configuration of
I just wanted to add my own JSON body parser, like Oj. I looked and did as described in the documentation, but got an error in the RSpec tests.
NoMethodError: undefined method `empty?' for #<OjParser:0x0000000101363df8> return DEFAULT_BODY_PARSERS if parser_specs.empty? ^^^^^^^
I saw that the
empty? method is missing somewhere and added it to my custom parser. But I don't understand where it is being called from.
The working version of the code looks like this:
But I'm not sure if this fix is in the right place.
# config/app.rb config.middleware.use :body_parser, OjParser.new # lib/oj_parser.rb class OjParser def mime_types ['application/json'] end def parse(body) Oj.load(body) unless body.empty? end # dummy method def empty? false end end
I created pull request for guide, but we need to find a place in the code where to fix it:
rulesis embedded in
include Deps['utils.email_validator'], but I notice in my spec, I just pass that dependency in on the initializer along with the param keys. What's to stop them conflicting and user input overriding a dependency?