by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • May 25 09:50
    k0va1 starred dry-rb/dry-monads
  • May 22 10:57
    solnic commented #146
  • May 21 22:24
    armstnp edited #125
  • May 21 22:23
    armstnp edited #125
  • May 21 22:17
    armstnp labeled #125
  • May 21 22:17
    armstnp opened #125
  • May 21 10:54
    jezstephens commented #146
  • May 21 09:25
    solnic labeled #146
  • May 21 09:23
    solnic commented #146
  • May 20 17:41
    jezstephens labeled #146
  • May 20 17:41
    jezstephens opened #146
  • May 19 21:29
  • May 19 13:26
    Springok starred dry-rb/dry-monads
  • May 16 22:52
    flash-gordon commented #402
  • May 16 22:51

    flash-gordon on master

    Fix Constructor custom method d… Merge pull request #402 from ti… (compare)

  • May 16 22:51
    flash-gordon closed #402
  • May 16 19:02
    timstott commented #401
  • May 16 18:59
    timstott opened #402
  • May 16 17:18
    flash-gordon commented #401
  • May 16 11:07

    github-actions[bot] on release-1.2

    Merge pull request #401 from ti… (compare)

Simon Schmid
@sled
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
Fran Worley
@fran-worley
@AMHOL can you raise an issue and I'll update the predicate before the next ruby gems release?
Andy Holland
@AMHOL
@fran-worley had a second look and I'm not 100% sure that's the case now
So Range#include? should work I think?