Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 02 21:35
    leonovk starred hanami/hanami
  • Dec 02 18:25
    worstpractice starred hanami/hanami
  • Dec 02 13:29
    mikebaldry commented #1265
  • Dec 02 11:19
    preetpalS starred hanami/hanami
  • Dec 02 10:26

    timriley on add-equalizer-to-callback-chain

    (compare)

  • Dec 02 10:26

    timriley on main

    Make chains comparable via #== … (compare)

  • Dec 02 10:26
    timriley closed #406
  • Dec 02 10:24
    timriley synchronize #406
  • Dec 02 10:24

    timriley on add-equalizer-to-callback-chain

    Update CHANGELOG (compare)

  • Dec 02 08:38

    timriley on 2.0.x

    Update CHANGELOG for v2.0.0 (#1… (compare)

  • Dec 02 08:38
    timriley closed #1263
  • Dec 02 08:37
    timriley commented #1263
  • Dec 02 08:16

    depfu[bot] on update

    (compare)

  • Dec 02 08:16

    jodosha on main

    Update hanami-utils to version … (compare)

  • Dec 02 08:16
    jodosha closed #200
  • Dec 02 08:16
    jodosha milestoned #200
  • Dec 02 08:16
    jodosha milestoned #200
  • Dec 02 08:15
    jodosha assigned #200
  • Dec 02 08:12
    jodosha labeled #1267
  • Dec 02 08:12
    jodosha assigned #1267
Sean Collins
@cllns

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)

Seb Wilgosz
@swilgosz
Hi all! Because Hanami 2.0 comes without the Persistence Layer configured, I've prepared a guide how to integrate ROM from scratch for anyone wanting to play with it: https://hanamimastery.com/episodes/28-configure-rom-from-scratch. Hope it helps!
Dima Boyko
@dimaboyko
Hi folks,
i am looking for an advise regarding usage of hanami/view. Would you suggest to use that for API presenters ? Or this is more focused on html template rendering ? In case of a api-only microservice, what recommendations do you have for placing exposure logic ? i am looking at Roar, grape-entity and hanami/view.
Seb Wilgosz
@swilgosz
@dimaboyko i do plan to play with dry-view in my next api application but have not strong opinion on this yet.
Seb Wilgosz
@swilgosz

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:
https://tally.so/r/n0QRgj

If you’ll hit the checkbox at the top and fill in the twitter handle, I’ll share your feedback with the world :)
Thanks!

Sebastjan Hribar
@sebastjan-hribar
Hey, can someone help me with variable substitution in .env.production?
Sebastjan Hribar
@sebastjan-hribar
Hi, I'm getting this error when deploying with Docker: Errno::EACCES: Permission denied @ rb_sysopen - hanami_log/production.log. I had to create the file under my user with sudo privileges, but Hanami can't write to it either.
hsynaccodeing
@hsynaccodeing
@swilgosz Hi, maybe not the most proper channel to mention this but I have create a small PR for the jay_doubleu_tee gem but haven't gotten any feedback for it for quite sometime now. Just wanted to ping you here, and thanks for the gem! hanamimastery/jay_doubleu_tee#3
2 replies
Simon Thiboutôt
@masterT

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.

MyJob.enqueue

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?

4 replies
Marwan Rabbâa
@waghanza
Hi,
I have /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
5 replies
Dima Boyko
@dimaboyko
Hi folks,
i am looking for opinion/advise on parameter parsing with hanami-controller.
Where do you draw the line between using params block within the action and using standalone hanami-validations objects ?or maybe i should go directly with dry-validations ?
Furthermore, what if i need to remap some of the fields from params before processing in inside repository ? (for instance: from http payload i am getting user_id, but would like to pass admin_user_id to 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 ?
sprock68
@sprock68:matrix.org
[m]
Hello, I'm running the tutorial for 1.3 & getting 'Capybara::ElementNotFound:Unable to find xpath "/html" ' when running 'bundle exec rake' after setting up 'apps/web/templates/home/index.html.erb'. Thanks for any help.
Edouard
@inouire_twitter
Amazing !
In the "How can I try it?" part, shouldn't there be a bundle install between cd bookshelf and bundle exec hanami --help ? or is it specific to each ruby setup ? (rbenv here)
Edouard
@inouire_twitter
-> bonus question: what would be the best doc ressource to poke around with this RC ? thanks !
Seb Wilgosz
@swilgosz
In two weeks should be released official guides, in the meantime we have some draft emerging, https://deploy-preview-114--hanami-guides.netlify.app/v2.0/architecture/slices/
You can check it if you'll keep in mind it's not finished
Edouard
@inouire_twitter
thanks @swilgosz
Alexey Melezhik
@melezhik
Hi guys! I am building CI service with support of many languages, Ruby included . I wonder if hanami needs the one ? I know you already have some setup for GH action Ubuntu . My service can do out if the box arch Linux/ Debian / Ubuntu / Alpine CI tests. I can drop a simple example if you are interested.
Armin
@wuarmin
Hello, does somebody know how I can fix following dep-mismatch?
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 want to install rom and rom-sql beside 2.0.0.rc1
Dima Boyko
@dimaboyko
Hi folks, would appreciate a hint with the issue i am having using rc1 https://discourse.hanamirb.org/t/standalone-testing-of-actions-in-rc1/716
Jerzy Sładkowski
@sysadm
Hi guys. Who can help me with the "simple problem" - probably I can't find good documentation. I can't pass through variable, defined on application_controller level to view (partial). Keyword expose doesn't work. So how?
And, btw, do we have any helper to pickup current request with path and params instead of reinvent the wheel based on rack session?
Matthew Weitzel
@mweitzel
This message was deleted
Trevor Turk
@trevorturk_twitter
Hello, I'm looking to configure the "alba" gem to automatically configure itself when in the context of a Hanami app. (In a Rails app: Alba.inflector = :active_support, in a Hanani app: Alba.inflector = :dry.) I believe I found the "correct" way to do this in Rails (https://github.com/okuramasafumi/alba/pull/274/files) but I'm having trouble finding a similar option in Hanami. I'm looking through the latest RC and I see it's easy to manually register a provider within your app, but I'm wondering if there's some way for a non-hanami gem to "inject" itself into a Hanami::App initialization. (Basically I want to have first class support for Rails/Hanami so the user can avoid creating an initializer.)
No worries at all if this isn't possible (or not advisable) but I'd love any advice from someone with more experience than me!
1 reply
Trevor Turk
@trevorturk_twitter
Jignesh Gohel
@jignaysh_twitter

Hello,

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 ROM.
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>'
17 replies
I also tried class Doctors < ::ROM::Relation[:sql] but no luck
Jignesh Gohel
@jignaysh_twitter

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.

Thanks.

9 replies
Masanori Ohnishi
@MasanoriOnishi

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?

https://guides.hanamirb.org/v1.3/actions/share-code/

7 replies
Jignesh Gohel
@jignaysh_twitter

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)
https://rom-rb.org/5.0/learn/repositories/quick-start/
https://hanamimastery.com/episodes/9-guide-to-models-in-hanami-and-rom

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:

  1. 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.

  2. Also ROM's 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.

Thanks.

2 replies
Masanori Ohnishi
@MasanoriOnishi

I have a question about hanami v2.

I use hanami/interactor now with hanami v1, but I found hanami/interactor was removed from hanami v2.
https://github.com/hanami/utils/blob/main/CHANGELOG.md#v200beta1---2022-07-20

Does Anyone know why hanami/interactor was removed?
And how we should change the old interactor? (For example we think we'll change expose to attr_reader and error! method to raise. Is it the right way in hanami v2? ref: https://docs.hanamirb.org/1.3.3/hanami/interactor)

1 reply
Luca Guidi
@jodosha

@/all Hanami 2.0.0 is finally here! <3

https://twitter.com/hanamirb/status/1595029998737293312

2 replies
Chris Schneider
@cschneid
It looks like templating is just up to the end user to figure out? I don't see any docs in 2.0 regarding the view layer, just response.body = <your problem> ?
Not that templating engines are hard to setup, just wondering if I missed something pre-decided or built in
Seb Wilgosz
@swilgosz
Templating is not done for 2.0, will be added with 0ersistance in 2.1. for now yes, You need to figure it out, but I will prepare a tutorial very soon on Hanami Mastery
Maxim Gurin
@Maxim-Gurin

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'
[1392505] Puma starting in cluster mode...
[1392505] * Puma version: 6.0.0 (ruby 3.1.2-p20) ("Sunflower")
[1392505] *  Min threads: 5
[1392505] *  Max threads: 5
[1392505] *  Environment: development
[1392505] *   Master PID: 1392505
[1392505] *      Workers: 2
[1392505] *     Restarts: (✔) hot (✖) phased
[1392505] * Preloading application
[1392505] * Listening on http://0.0.0.0:2300
$ HANAMI_PORT=5000 bundle exec puma -C config/puma.rb
[1392728] Puma starting in cluster mode...
[1392728] * Puma version: 6.0.0 (ruby 3.1.2-p20) ("Sunflower")
[1392728] *  Min threads: 5
[1392728] *  Max threads: 5
[1392728] *  Environment: development
[1392728] *   Master PID: 1392728
[1392728] *      Workers: 2
[1392728] *     Restarts: (✔) hot (✖) phased
[1392728] * Preloading application
[1392728] * 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.

Jignesh Gohel
@jignaysh_twitter

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

Server logs

[10080] Puma starting in cluster mode...
[10080] * Puma version: 6.0.0 (ruby 3.1.2-p20) ("Sunflower")
[10080] *  Min threads: 5
[10080] *  Max threads: 5
[10080] *  Environment: development
[10080] *   Master PID: 10080
[10080] *      Workers: 2
[10080] *     Restarts: (✔) hot (✖) phased
[10080] * Preloading application
[10080] ! 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?

Aleksey Kurepin
@foxweb

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 middleware body_parser.
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:
hanami/guides#159

2 replies
Michael Baldry
@mikebaldry
Hey there, in an Hanami::Action::Params is it possible to use rules?
oh nevermind, rules is embedded in params block
Michael Baldry
@mikebaldry
Next question - I'm injecting a dependency in to my Params with 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?
Michael Baldry
@mikebaldry
and back to the previous question, the rules block doesn't seem to get called at all
Michael Baldry
@mikebaldry
great work by the way!
Paul Sadauskas
@paul
Are there any suggestions or examples on how to incorporate a static asset build pipeline with a hanami app?