Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 13 15:58
    rokhimin starred dry-rb/dry-matcher
  • Dec 13 08:53
    flash-gordon labeled #376
  • Dec 13 08:44
    solnic commented #376
  • Dec 12 21:34
    flash-gordon commented #376
  • Dec 12 21:34
    flash-gordon labeled #376
  • Dec 12 21:34
    flash-gordon opened #376
  • Dec 12 19:32
    RyanLafferty starred dry-rb/dry-types
  • Dec 12 05:53
    technofreak starred dry-rb/dry-monads
  • Dec 12 00:14
    thekuwayama starred dry-rb/dry-monads
  • Dec 11 09:29
    blasterun starred dry-rb/dry-monads
  • Dec 11 08:34
    flash-gordon closed #115
  • Dec 11 08:34
    flash-gordon commented #115
  • Dec 11 08:31

    flash-gordon on v1.3.3

    (compare)

  • Dec 11 08:30

    flash-gordon on master

    Bump version to 1.3.3 (compare)

  • Dec 11 08:30

    flash-gordon on master

    Update CHANGELOG (compare)

  • Dec 10 23:46
    johnmaxwell commented #116
  • Dec 10 21:54

    flash-gordon on master

    Halt with mutable backtrace Ex… Merge pull request #116 from jo… (compare)

  • Dec 10 21:54
    flash-gordon closed #116
  • Dec 10 21:54
    flash-gordon commented #116
  • Dec 10 21:49
    johnmaxwell commented #116
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?
Fran Worley
@fran-worley
I'll try it in my unreleased branch of Dry-V. If that works then it will be fixed when we can release dry logic on ruby gems.
I don't see that it will make much difference as I've not actually changed anything but the names really...
Simon Schmid
@sled
there's something interesting here:
```
  predicate(:included_in?) do |list, input|
    list.include?(input)
  end
  predicate(:includes?) do |value, input|
    input.include?(value)
  end
why are the arguments the other way around?
Fran Worley
@fran-worley
Yeah, that is not actually being used in DRY-V yet
dry-rb/dry-logic#9
the idea being: input_value.included_in?(list) vs input_value.includes?(value)