Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Andrew Kozin
@nepalez
@timriley thanks! with my rungnish writing a post is too time-consuming challenge. I'd postpone it to the weekend
Tim Riley
@timriley
@nepalez no worries, take your time :) BTW, if you need a hand with proof-reading/minor editing, I'm happy to help.
Tim Riley
@timriley
dry-web just got its first rubygems release: http://rubygems.org/gems/dry-web
Tim Riley
@timriley
I also started documenting the skeleton that we use for icelab dry-web projects: https://github.com/icelab/dry-web-skeleton
Fran Worley
@fran-worley
@timriley looks good I'll try and find the time to have a play with it at the weekend!
Tim Riley
@timriley
@fran-worley cool! Would love your feedback on how things feel. In the next 2 months, I want to focus on massively improving the dry-web experience for newcomers.
S/massively/as best I can/ :)
Tim Cooper
@coop
Tim Riley
@timriley
Oh, thanks @coop!
Benjamin Klotz
@tak1n
@timriley awesome, I think I will soon start a toy project with dry-web etc :)
Tim Cooper
@coop
It was a good explaination without touting that “it is better”. Well done.
Fran Worley
@fran-worley
@timriley you have the power of words my friend. I avoid trying to put my thoughts in comments as I just sound opinionated... Well said!
Tim Riley
@timriley
Ta :blush:
@tak1n great! Would love to hear how you go. Let me know if you have question.
BTW, at Icelab we're currently building our now company site as a dry-web app started from this skeleton. It's still very early, but it may serve as a helpful point of reference. It's on GitHub as icelab/berg.
Benjamin Klotz
@tak1n
@timriley cool thx :D
Tim Riley
@timriley
I hope to bring our other young example app (icelab/Alpinist) up to date soon too. that one hasn't been touched since December, and we've progressed our dry-web setup a fair bit since then.
Benjamin Klotz
@tak1n
yea I have seen it, I was curious how dry-v was used in dry-web and in alpinist you subclass Dry::V::Schema which is no longer possible I think
Tim Riley
@timriley
Yeah. Old school and now broken :grimacing:
Fran Worley
@fran-worley
@timriley is it worth adding your explanation of dry-v #113 to the dry-rb.org site?
It might be useful to just explain the purpose of the
Tim Riley
@timriley
Yeah, I reckon.
Kuba Krzempek
@kubakrzempek

Hi everyone, I'm writing a form object powered by dry-validation. Let's say the form has two keys - :code and :organization_id.
I want to validate whether a pair [:code, :organization_id] is unique in my db, yet I'm failing in doing so.
First I though about using rule(uniq_code: [:code, :organization_id]) but it clearly wants me to run predicates on the keys I've passed into it, so I decided to go with my custom predicate and ended up with the following

Create = Dry::Validation.Form do
  key(:code).required(uniq?: "organization_id")
  key(:name).required
  key(:countries_id).required
  key(:description).required
  key(:organization_id).required
  key(:active).required

  configure do
    option :market_repo, WheelsApp.instance["repositories.market"]

    def uniq?(organization_id, value)
      # query logic here
    end
  end

How can I pass to uniq? method a value of :organization_id that comes from object I've passed into the form?

I tried with value(:organziation_id) but that returns something like an ast graph
Tim Riley
@timriley
@kubakrzempek if you want to work on the two at once, I think you need to make a "high level rule" (it's in the docs) which could then pass those two values to a predicate to check for uniqueness of both
Simon Schmid
@sled
not sure whether it works though ;)
Kuba Krzempek
@kubakrzempek
@timriley @sled thank you for your answers. As you suggested I went back on "high level rule" track and it looks like this now
https://gist.github.com/kubakrzempek/f6c15643b9adae7e3de27a6b946aee30
but it still doesn't work, because sequel queries expect organization_id and code to be values, not Dry::Validation::Schema::Rule objects.
I commented the unique? method's body and returned false explicitly, and the rule(:uniq_code_organization) failed, because it didn't expected to receive a FalseClass object.
Do you know any other way to implement block assigned to rule?
Andy Holland
@AMHOL
@kubakrzempek you know you passed the arguments to unique? in the wrong order?
@kubakrzempek I'm not sure how to do what you're trying to do but looking at http://dry-rb.org/gems/dry-validation/high-level-rules/ and http://dry-rb.org/gems/dry-validation/custom-predicates/ what you have so far isn't right
Christopher Dennl-Ortega Arrieta
@cdennl
@AMHOL no it is not wrong order
Andy Holland
@AMHOL
It's also better to have your repositories return materialized results, rather than having query logic leak out into other parts of your application
Christopher Dennl-Ortega Arrieta
@cdennl
@AMHOL the order is reversed
Andy Holland
@AMHOL
Ahh OK
Christopher Dennl-Ortega Arrieta
@cdennl
got trapped by this as well a week ago
but solnic meant this is intended
Simon Schmid
@sled
    rule(code_organization_uniq: [:code, :organization_id]) do |code, organization_id|
      unique?(code, organization_id)
    end
can you give me the .inspect output of the arguments?
is it a <#Rule ...> object?
Andy Holland
@AMHOL
It looks like the return value from rule should be a predicate
Simon Schmid
@sled
it looks like the .value method evaluates a predicate and just returns true/false
Andy Holland
@AMHOL
I'm thinking maybe this isn't supported yet
dry-rb/dry-validation#105
Christopher Dennl-Ortega Arrieta
@cdennl
@kubakrzempek your gist should work, if not then it is a sequel problem, because thats how i wrote my own predicates as well, take a look:
panigrah
@panigrah
in the new dry-v how do i check for property is empty or if present then it is inclusion: {in: 0..5}
Christopher Dennl-Ortega Arrieta
@cdennl
module Dagavel::Predicates
  include Dry::Logic::Predicates

  predicate( :is_conversion_correct? ) do |exchange_rate_usd_points, points, usd|
    points_in_usd = ( Auction.convert_points_to_money( points, exchange_rate_usd_points ) * 100 ).floor
    usd = ( usd * 100 ).floor

    usd == points_in_usd
  end
end

...

rule( start_bid_conversion_is_correct: [ :start_bid_in_points, :start_bid_in_usd, :exchange_rate_usd_points ] ) do
  |start_bid_in_points, start_bid_in_usd, exchange_rate_usd_points|
        ( start_bid_in_points.int? & start_bid_in_usd.float? & exchange_rate_usd_points.int? ).then(
            start_bid_in_usd.is_conversion_correct?( start_bid_in_points, exchange_rate_usd_points )
        )
      end
Andy Holland
@AMHOL
@cdennl @kubakrzempek what version/branch are you both using?
Christopher Dennl-Ortega Arrieta
@cdennl
reform 2-2 branch, dry-v 0.7.4
0.7.3 sorry