Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 10:40
    jodosha synchronize #199
  • 10:40

    jodosha on tree-rewrite

    README, CHANGELOG, and API docs (compare)

  • Feb 17 22:40

    depfu[bot] on update

    (compare)

  • Feb 17 22:40
    depfu[bot] closed #572
  • Feb 17 22:40
    depfu[bot] commented #572
  • Feb 17 22:16
    depfu[bot] labeled #574
  • Feb 17 22:16
    depfu[bot] opened #574
  • Feb 17 22:16

    depfu[bot] on update

    Update dry-types to version 1.3… (compare)

  • Feb 17 21:11
    james947 starred hanami/hanami
  • Feb 17 19:56
    adam12 starred hanami/router
  • Feb 17 11:25
    JonathanFerreira starred hanami/hanami
  • Feb 17 09:49
    DangerDawson commented #287
  • Feb 17 00:08
    timriley commented #1029
  • Feb 16 18:45
    akabiru starred hanami/hanami
  • Feb 16 13:45

    solnic on unstable

    Add ci workflow (#1030) (compare)

  • Feb 16 13:45
    solnic closed #1030
  • Feb 16 00:06
    solnic commented #1030
  • Feb 15 23:36
    cllns commented #1030
  • Feb 15 23:15
    solnic edited #1030
  • Feb 15 23:10
    solnic edited #1030
Panayotis Matsinopoulos
@pmatsinopoulos
@kaikuchn @katafrakt thank you.
Paweł Świątkowski
@katafrakt
@unleashy webpacker_cli is indeed a no-go. I misunderstood its concept and goal.
unleashy
@unleashy
yeah, unfortunately we'll probably have to make something from the ground up :grimacing: or somehow hack webpacker to work with hanami
Paweł Świątkowski
@katafrakt
FWIW I created super-minimal example of adding Parcel (because I kind of hate Webpack) to Hanami app: https://gitlab.com/katafrakt/hanami-with-parcel
Panayotis Matsinopoulos
@pmatsinopoulos

Hello Good People!

We would like to incorporate real-time server to browser communication into our Web application which is served by a Hanami REST API. Is that possible to implement web sockets between our Web Application and our Hanami server? Can we use something similar to what Rails has, i.e. ActionCable?

Thank you!

Paweł Świątkowski
@katafrakt
@pmatsinopoulos take a look at LiteCable (https://github.com/palkan/litecable). I personally have never used it but I've heard it works with pretty much any Rack-based stack.
Panayotis Matsinopoulos
@pmatsinopoulos
nice! @katafrakt thank you very much!
unleashy
@unleashy
@katafrakt thanks! i'll check it out. why do you dislike Webpack, by the way?
oh yeah—has anyone gotten Zeitwerk to work with hanami?
Kok Hung Cheah
@ckhung5
@kaikuchn Thanks for the response. Yes my team is implementing a one-off data migration script using rake task and delete off the code after that.. I am very curious about how do we track this changes or how others track that this data migration had been done before? Any thoughts?
Panayotis Matsinopoulos
@pmatsinopoulos

Hello Good People,

I am learing Hanami Validations and trying to build a custom predicate. In fact, I would like to create a rule like this:

rule(check_dates: [:check_in, :check_out]) do |check_in, check_out|
  check_in < check_out
end

This fails with:

< predicate arity is invalid

which makes sense since the documentation says that we cann’t write arbitrary Ruby inside the predicate block.

But, how can I implement such a rule? what is the best practice for this case?

Thank you very much in advance.

Paweł Świątkowski
@katafrakt
Paweł Świątkowski
@katafrakt
@unleashy I feel that webpack is unnecessarily complex and webpack configs are new Makefiles - nobody can write them, people just copy them from other projects and adjust by trial-and-error ;)
Panayotis Matsinopoulos
@pmatsinopoulos
@katafrakt …Oooh. I didn’t know that predicates could take arguments. Thank you very much!
Panayotis Matsinopoulos
@pmatsinopoulos
@katafrakt I think there is a problem to the execution of the predicate which can be confirmed by the results of running your gist. date1 with value Date.new(2020, 2, 20) should not be < date2 with value Date.new(2010, 2, 1), which means that validate.success? should have returned false and not true in the first invocation. Equivalently, the 2nd invocation should have returned true, because date2 is indeed less than date1. I have done some further investigation and I see that the run-time values of the arguments of the block of the predicate, i.e. current, other, are reversed. I.e. the current takes the value of the check_in date and the other takes the value of the check_out date. So, am I correctly suspecting the there is a bug in how predicate invokes the block? Or shall I just reverse the |current, other| to |other, current| and get away with it?
Paweł Świątkowski
@katafrakt
@pmatsinopoulos you are correct. It should be predicate :before? do |other, current|. It seems that predicate arguments come first and the actual value comes last.
Panayotis Matsinopoulos
@pmatsinopoulos
@katafrakt Thank you!
Paweł Świątkowski
@katafrakt
this is poorly documented, unfortunately
Panayotis Matsinopoulos
@pmatsinopoulos

Hello Good People,

I am implementing an API on Hanami and when the API is called from a browser, the browser does a pre-flight check and sends an OPTIONS request to the end-point. I am thinking about adding the following entry to my config/routes.rb file:

options '/*', to: ->(_) { [200, { 'Allow' => 'OPTIONS, HEAD, GET, POST, PUT, PATCH, DELETE' }, ['']] }

so that all the OPTIONS requests, on any path, to return all the verbs. Is that a good practice? Is there anything else that I should do better?

Thank you very much in advance.

Kai Kuchenbecker
@kaikuchn

But that would be a lie, wouldn't it? What if some endpoint does not support a http verb? But you claimed it did. I don't think this is a good practice.
Also, why is the browser doing a preflight request? Is this CORS?

Oh, and you should probably implement such things in your reverse proxy. That way is much faster than relying on your ruby app for an answer to OPTIONS requests.

Panayotis Matsinopoulos
@pmatsinopoulos

@kaikuchn Yes it is a CORS request. And your points are very good.

I will see into the reverse proxy suggestion. Although I don’t know how

Thank you.

Kai Kuchenbecker
@kaikuchn
Here's an example for nginx, but I don't recommend copy & pasting it since it is NOT secure: https://enable-cors.org/server_nginx.html
Panayotis Matsinopoulos
@pmatsinopoulos
Thank you @kaikuchn
Kai Kuchenbecker
@kaikuchn
I think the minimum you should do is restrict the Origin of the CORS requests.
I.e., replace '*' with your domain
Panayotis Matsinopoulos
@pmatsinopoulos
Sure.
Jonatas Daniel
@jonatasdaniel
Hey guys,
I am new with hanami and I would like to know if there is a way to create the app without html, templates and all stuff that’s not used by an API?
Edouard
@inouire_twitter
This message was deleted
I'd say just delete them manually :)
Edouard
@inouire_twitter
@jodosha Change of plans, unfortunately I won't be able to attend Paris.rb :(
are there some people interested for an informal meetup somewhere around the dates of the conf?
unleashy
@unleashy
@katafrakt that's really accurate haha. I work with webpack a lot and that's just exactly what happens. I'll take a look at parcel since it seems awesome!
@toshizooooooo_twitter
Hello,
How do I set both the primary DB and replica DB (read only) connections in the Hanami.configure?
I want to set up the following site. https://github.com/jeremyevans/sequel/blob/master/doc/sharding.rdoc
Panayotis Matsinopoulos
@pmatsinopoulos

Hello Good People,

I am trying to get the Author of a Book within a Book#to_enqueued_item() method like this:

class Book < Hanami::Entity
  def to_enqueued_item
    bwa = book_with_author
    {
      title: title,
      isbn: isbn,
      author_code: bwa.author.code
    }
  end

  private

  def book_with_author
    return self unless author.nil?
    BookRepository.new.find_with_author(id)
  end
end

Where the BookRepository defines a Belongs To association to the Author like in the example here

I wanted to ask whether my #to_enqueued_item() implementation looks good in terms of practice, since the instance of the Book that I may have at hand might not have the author.

thank you in advance.

Kai Kuchenbecker
@kaikuchn
I see one issue with your implementation: nil can mean both that the author wasn't loaded yet or that the book does not have an author.
Personally I'm a fan of null objects, i.e., implement a NullAuthor and return it if a book does not have an author. That eliminates many nil checks and you also solve the above issue.
Panayotis Matsinopoulos
@pmatsinopoulos
Very good point, only that I can’t see a book without an author in my business domain. But, yes, I do like NullObject pattern too. I will consider. Thank you very much.
Kai Kuchenbecker
@kaikuchn
If you can't see a book without an author, then restrict your database schema such that a book must have an author.
And then the problem is solved as well.
Panayotis Matsinopoulos
@pmatsinopoulos
I do have this constraint already set. But the BookRepository does not return the associated object by default. This is what Hanami does according to its design. Am I wrong?
Kai Kuchenbecker
@kaikuchn
yeah, that's what it does.
I just thought that you implied that a author may not exist, but I see I misread :)
Panayotis Matsinopoulos
@pmatsinopoulos
ok. Thank you :-)
Martin Becker
@Thermatix
Hello, I'm trying to implement Websockets using anycable via litecable, I've got most of the base code done but I'm trying to build a spec for it and I can't seem to find any information on how to build specs for WebSockets that isn't rail's related, so does any one have information?
Kai Kuchenbecker
@kaikuchn
Nope, best guess would be to ask the anycable/litecable people?
Martin Becker
@Thermatix
Thanks, I actually got a good suggestion to just re-use what litecable did for there own specs so I'm doing that, taking a bit of setup but I'm getting there
Jeff Dickey
@jdickey

Has anybody done a Hanami project that does not make use of a SQL database, but serialises to and from a structured flat file used by other, third-party code. (Think of a Gemfile.lock file, for example.) After skimming the Hanami::Model and Sequel codebases, I’m left with the impression that I should create bespoke Serialiser and Deserialiser services that consume and emit raw Hashes of Entity objects defined using a manual schema.

While I’ve convinced myself lthat it should be possible to make this work, I haven’t convinced myself lthat this is the best/most “Hanami-like” way to do things. (Better) ideas gratefully welcomed.

Edouard
@inouire_twitter
I'd personnaly go for a solution like you presented
as long as the concepts are really decoupled and boundaries well defined I'd say you're doing "the Hanami way" :D
Jeff Dickey
@jdickey
Or at least the sensible way. Thanks, @inouire_twitter; in five days I haven't been able to come up with a better plan, so I'll go that route and see what blows up in my face. (Forty years in software assures me that something certainly will.) :wink: