by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jul 07 18:01
    depfu[bot] labeled #200
  • Jul 07 18:00
    depfu[bot] opened #200
  • Jul 07 17:56

    depfu[bot] on update

    Update rubocop to version 0.87.0 (compare)

  • Jul 07 17:54
    depfu[bot] labeled #374
  • Jul 07 17:54
    depfu[bot] opened #374
  • Jul 07 17:52

    depfu[bot] on update

    Update rubocop to version 0.87.0 (compare)

  • Jul 07 11:40

    timriley on unstable

    (compare)

  • Jul 07 11:40

    timriley on unstable

    Automatically apply application… (compare)

  • Jul 07 11:40
    timriley closed #320
  • Jul 07 11:37
    timriley synchronize #320
  • Jul 07 11:37

    timriley on unstable

    Tweak name Define regular method This was… Apply configuration from applic… and 6 more (compare)

  • Jul 07 11:12
    timriley synchronize #320
  • Jul 07 11:12

    timriley on unstable

    Use unstable branch again (compare)

  • Jul 07 11:07

    timriley on unstable

    (compare)

  • Jul 07 11:07

    timriley on unstable

    Make Hanami::Action::Configurat… (compare)

  • Jul 07 11:07
    timriley closed #1065
  • Jul 07 11:01
    timriley synchronize #1065
  • Jul 07 11:01

    timriley on unstable

    Use unstable branch again (compare)

  • Jul 07 07:27

    jodosha on unstable

    Rubocop master 0.81 (#198) Merge branch 'master' into deve… Merge branch 'develop' into uns… (compare)

  • Jul 07 07:26

    jodosha on develop

    Rubocop master 0.81 (#198) Merge branch 'master' into deve… (compare)

kristjan-brezovnik
@kristjan-brezovnik
Dumb question. I have a json file in my assets/javascript folder of my app. This is the same folder where the js file from which I want to load it is located. Both files are also in the public folder under the app's assets. But I get a 404 error (not found) when trying to load it. The jQuery.getJSON function is working fine from a vanilla html file, so I don't think this is a jQuery issue. What am I missing? Is the file in the wrong location?
Armin
@wuarmin
hello, I do not understand what's the last timestamp in hanami-http-log:
[backend] [INFO] [2020-06-18 08:03:24 +0200] HTTP/1.0 GET 200 10.19.1.11, 10.10.10.95 /administration/items 18682 {"environment"=>"production", "from"=>"2020-06-16", "until"=>"2020-06-18"} 2020-06-17 23:06:55 +0200
What means the last part of the log? 2020-06-17 23:06:55 +0200?
Armin
@wuarmin
Hey, another question: Puma-thread-count should correspond to the connection-pool size. How I can define the connection-pool-size of Hanami-model (romrb, sequel under the hood)?
Danny Santos
@DannySantos
@wuarmin If you’re referring to the +0200 part then it represents the timezone. I think this ones specifically: https://en.wikipedia.org/wiki/UTC%2B02:00
@sebastjan-hribar Interesting, I’ve just implemented a self-referential table on my app, I hope it can still do everything I need it to!
Armin
@wuarmin
@DannySantos thanks, no I mean the whole timestamp? The request was executed on 2020-06-18 08:03:24 +0200, but what about 2020-06-17 23:06:55 +0200 (what has a request of this morning has to do with a timestamp of last night)?
Danny Santos
@DannySantos
Oh sorry, I see what you mean. Yeah that’s strange, I’m not sure why there’s a second timestamp. The only thing I notice is that you are sending a date range through in your parameters and the timestamp appears to be directly in the middle of those two dates? I’m not sure if that could be something to do with it.
Danny Santos
@DannySantos
@wuarmin You could test that theory by sending in a different date range and seeing if the timestamp is still in the middle
@sebastjan-hribar FYI I am able to retrieve self-referential results, but that is just using a has_many relationship, not has_many through:
Armin
@wuarmin
@DannySantos ok, no, this has nothing to do with the specific request. This timestamp get logged at every request.
Danny Santos
@DannySantos
@wuarmin In that case I’m not too sure, there doesn’t seem to be anything in the logger file that explains this either: https://github.com/hanami/utils/blob/master/lib/hanami/logger.rb
Armin
@wuarmin
@DannySantos I will do some further investigation... Thanks for your help!
Danny Santos
@DannySantos
@wuarmin No worries mate, good luck
Sebastjan Hribar
@sebastjan-hribar
@DannySantos Thank you for the information. Let me know how it goes. We'll keep the workaround for has_many through: for now. It's not a problem. As long as the reason for not working is known.
Armin
@wuarmin
@DannySantos if I change logger-formatter to json, the key of the weird timestamp is elapsed.
Armin
@wuarmin
Why elapsed is represented as timestamp?
Danny Santos
@DannySantos
@wuarmin Hmm that is weird. I suppose the key question is, elapsed since what? Have you got multiple examples of this log? Can you compare how the elapsed timestamp changes each time, and maybe figure out what its relationship is to the request timestamp?
Yuriy Tsemashko
@azzz

Hi there. What is a better way to work with mongodb in hanami? I found hanami-mongoid gem that implements mongoid-based repositories but the gem has not been updated for 15 months already.

Of course I can get rid off hanami models and repositories and use mongoid directly but then I have concerns why I can't use just sinatra

Armin
@wuarmin
@DannySantos here's the commit at rack, where they moved from Time.now to a monotonic clock: rack/rack@743f29d
With that Hanami's CommonLogger cannot calculate elapsed properly:
      now    = Time.now
      length = extract_content_length(header)

      msg = Hash[
        http:    env[HTTP_VERSION],
        verb:    env[REQUEST_METHOD],
        status:  status.to_s[0..3],
        ip:      env[HTTP_X_FORWARDED_FOR] || env[REMOTE_ADDR],
        path:    env[SCRIPT_NAME] + env[PATH_INFO].to_s,
        length:  length,
        params:  extract_params(env),
        elapsed: now - began_at #calculation fails
      ]
Armin
@wuarmin
we should move to:
now    = Rack::Utils.clock_time
Armin
@wuarmin
@azzz Checkout the hanami-mongoid gem. It is a very small gem. Maybe it helps you. If not, just use mongoid directly (like in Sinatra). Hanami is much more, than hanami model.
Armin
@wuarmin
I opened a PR (hanami/hanami#1061)
Danny Santos
@DannySantos
@wuarmin Great find! Maybe open an issue on the Hanami::Utils Github?
Armin
@wuarmin
@DannySantos I opened a PR
Danny Santos
@DannySantos
👍🏼
Armin
@wuarmin

@DannySantos do you have an answer to this question?

Hey, another question: Puma-thread-count should correspond to the connection-pool size. How I can define the connection-pool-size of Hanami-model (romrb, sequel under the hood)?

Danny Santos
@DannySantos
@wuarmin I think if you use the postgres URI format you can pass in additional parameters, maybe see if you can configure it there?
Armin
@wuarmin
@DannySantos you are right: hanami/model#168. Thanks!
Sebastian Nowak
@seban
I have one question regarding explicit return in interactors call methods. Is something like return unless something can be considered as good practice? Would it be better to fail! unless something?
Armin
@wuarmin
@seban I would use error! or fail! http://hanamirb.org/docs/1.0.0/Hanami/Interactor.html
Sebastian Nowak
@seban
Yeah, it looks like better option. Otherwise there is always successful? result returned. Thans Armin!
Danny Santos
@DannySantos
@seban Even better, you can integrate dry-monad and always return a monad, whether it fails or succeeds.
A little more complex to set up but you can get a really nice interactor pattern using monads
Sebastian Nowak
@seban
@DannySantos any valuable example?
Danny Santos
@DannySantos

@seban This article goes into it slightly: https://medium.com/adhawk-engineering/designing-services-with-dry-rb-fe850f8dd4b7

But it doesn’t describe how you can handle various results in your controller by calling your interactor with a block:

interactor.call(params) do |m|
  m.success do |user, msg|
    flash[:notice] = msg
    redirect_to routes.user_path(@user.id)
  end
  m.failure(:auth_error) do |user, msg|
    flash[:notice] = msg
    redirect_to routes.auth_error_path
  end
  m.failure do |user, msg|
    flash[:notice] = msg
    redirect_to new_session_path
  end
end

It’s a really great way to handle interactor results, sorry I don’t have a more in-depth example for you but you could google around if you’re interested in using it.

Sebastian Nowak
@seban
Ok, now it is clear what you wanted to say. I think I saw a similar approach in wisper gem. Thank for article will read it :bow:
Danny Santos
@DannySantos
👍🏼
Masanori Ohnishi
@MasanoriOnishi

I have a question.
hanami/model#294

How does everyone avoid creating anemic domain model ?
Although entities are the core of an application and should have methods related to domain logic, we can't add update method to them, because they are immutable objects.

In this article, he says that you should use repository for update process, but does it seem to be outflow of domain logic? ("anemic domain model")

Sebastjan Hribar
@sebastjan-hribar

I have a follow-up problem to my aggregate. The full gist is still here .
For the aggregate below I would like to filter by the translation_record's attribute as well. To get only records for a given language combination. I need this, because, as I stated before, the aliased self-relational association doesn't work yet in this version of Hanami Model.

class SegmentRepository < Hanami::Repository

  associations do
    has_many :translation_records
    has_many :segments, through: :translation_records, as: :target_segments
    belongs_to :language
  end

  def find_by_segment_match(source_text_for_lookup, source_lang, target_lang, sim_score, max_results)
    aggregate(:translation_records)
      .where {similarity(:content, source_text_for_lookup) > sim_score/100.00}
      .select_append {float::similarity(:content, source_text_for_lookup).as(:similarity)}
      .order {similarity(:content, source_text_for_lookup).desc}
      .limit(max_results)
  end

end

I've added a language_combination attribute to translation_records.

I want to do something like .where {translation_records.language_combination = "#{source_lang}_#{target_lang}". This yields: undefined method meta for TranslationRecord:Class

ippachi
@ippachi

@sebastjan-hribar

class UserRepository
  associations do
    has_many :posts
  end

  def find_with_posts_by_created_at(user_id, from: nil, by: nil)
    aggregate(:posts)
      .where(users[:id].qualified.is(id))
      .node(:posts) do |posts|
        posts.where(post_created_at_gt(from))
             .where(post_created_at_lt(by))
             .order(post_created_at_desc)
      end
      .map_to(User).one
  end

  private

  def post_created_at_gt(from)
    (posts[:created_at].qualified > DateTime.parse(from).to_time + 1)
  end

  def post_created_at_lt(by)
    (posts[:created_at].qualified < DateTime.parse(by).to_time + 1)
  end

  def post_created_at_desc
    posts[:created_at].qualified.desc
  end
end

Does this code help you?
I found node method at rom-rb documentation.
https://api.rom-rb.org/rom/ROM/Relation/Combined#node-instance_method

Sebastjan Hribar
@sebastjan-hribar
@ippachi YES! Thank you. :)
This works great:
def find_by_segment_match(source_text_for_lookup, source_lang, target_lang, sim_score, max_results)
    aggregate(:translation_records)
      .node(:translation_records) do |translation_records|
        translation_records.where(language_combination: "#{source_lang}_#{target_lang}")
      end
      .where {similarity(:content, source_text_for_lookup) > sim_score/100.00}
      .select_append {float::similarity(:content, source_text_for_lookup).as(:similarity)}
      .order {similarity(:content, source_text_for_lookup).desc}
  end
Matt Culpepper
@mculp
@ippachi thanks, that also helped me figure out the question I came to ask, lol
Sebastjan Hribar
@sebastjan-hribar
@ippachi :) that's great, but I spoke a bit too soon. The above code doesn't yield only segments for the .node condition of translation records, but I get back all segments. So I need to look how to change this. But still, I can access the translation_records.
Johannes von Bargen
@prosac
hi! a colleague at work implemented an internal app using hanami. since we are asked to run ruby 2.7 upwards he now seems to plan to port the app to rails. i would like to determine now how the opinions are regarding hanami on 2.7. running script/ci looks not too bad. just a lot of deprecation warnings regardning the changes in rubys argument handling (https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/). i also gave the tests of hanami/utils a try. similar outcome (making a quick spike to see if i could maybe get that fixed right now). but before i go on and run in the wrong direction: are there any ongoing efforts on porting hanami and its libs to ruby 2.7 as of now?
Viktor
@skcc321
I have the same question. There is not much contribution to hanami on Github, so people start afraid of using hanami because it can become unmaintained soon. If they could do some scheduled releases it would bring some confidence in the framework... But no... So looks like here is the only way - switch back to the worse arch but regularly updated rails...
Paweł Świątkowski
@katafrakt
Hanami 2.0 will work in 2.7 for sure. It's true that all efforts now go into it and 1.x feels a bit abandoned.
Viktor
@skcc321
do we have any ETA when 2.0 is gonna be released?
Jeff Dickey
@jdickey
...or at least with a beta-quality release that has a consistent set of Gems working together? Playing Whac-A-Mole® on 1.3.3 right now, and it's been going slowly enough that we've been tasked with reimplementing our original single-small-service Hanami code for the current project in Roda+dry-rb+sequel and Rails for comparative evaluation. If I can credibly say that our Hanami pain points are likely to be addressed by (e.g.) mid-August, we might be able to avoid all the drama