Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
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
Andy Holland
@AMHOL
Your rule returns the result of a predicate tho, so it's not the same as @kubakrzempek's
Christopher Dennl-Ortega Arrieta
@cdennl
yes you have to define a predicate
but he defined one as well
he just used inline definition
where mine resides in a module because i need it several times
Andy Holland
@AMHOL

Looks like changing rule to

    rule(code_organization_uniq: [:code, :organization_id]) do |code, organization_id|
      code.unique?(organization_id)
    end

Should fix it

Left a comment on the gist @kubakrzempek
Kuba Krzempek
@kubakrzempek
@AMHOL that works!!!
Thank you a milion!
Andy Holland
@AMHOL
Cool, np, and thanks @cdennl for pointing that out
Simon Schmid
@sled
half of dry-*'s awesomeness is this channel ;)
Kuba Krzempek
@kubakrzempek
Thank all of you for your help!
Christopher Dennl-Ortega Arrieta
@cdennl
np
Andy Holland
@AMHOL
@sled :D
Christopher Dennl-Ortega Arrieta
@cdennl
yeah predicates must run on rules it seems
Andy Holland
@AMHOL
@panigrah what do you mean by "empty"?
nil, and empty array, an empty string?
panigrah
@panigrah
@AMHOL it can be nil or empty string
Andy Holland
@AMHOL
Or an integer?
Christopher Dennl-Ortega Arrieta
@cdennl
optional(:my_string).maybe(size?: 0..5) in the old syntax
@panigrah
sorry didnt read that you asked forn ew syntax
Andy Holland
@AMHOL
Ahh, sorry, I was thinking the value should be between 1 and 5
panigrah
@panigrah

thanks! it also works for optional(:my_number).maybe(inclusion?: 1..5) BUT if I do the below

       schema = Dry::Validation.Schema do
          optional(:num).maybe(inclusion?: 1..5)
       end
       errors = schema.call(abc: '1', num: 6)

I get a NoMethodError. input.rb:86:inoptions_for_inclusion?': undefined method join' for 0..5:Range (NoMethodError)

Andy Holland
@AMHOL
@panigrah are you using the master branch?
Maybe try included_in? dry-rb/dry-logic@e649fad
Sorry I'm not much help, I haven't actually used dry-validation myself yet
panigrah
@panigrah
i wasn't on master. Switched to master and it works now. Thanks for the tip.
Andy Holland
@AMHOL
Cool
panigrah
@panigrah
and one other change I made - passed the 1..5 in an array. optional(:age).maybe(inclusion?:[1..5])
Andy Holland
@AMHOL
Hmm, would think it should work with a range
panigrah
@panigrah
So this works optional(:age).maybe(inclusion?: [1, 2, 3, 4, 5]) but this fails optional(:age).maybe(inclusion?: 1..5) on master. I spoke too soon - it was failing even on master - but the error was getting redirected so didnt realize.
Andy Holland
@AMHOL
Yeah, looking at dry-logic it doesn't support a range argument