Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
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)
Simon Schmid
@sled
ah now I get it :)
Fran Worley
@fran-worley
so we had to rename inclusion? and exclusion? to make it clear what the 2 do
Fran Worley
@fran-worley
@panigrah try optional(:age).maybe(inclusion?: (1..5)) I've got it working when the range is wrapped in parentheses
Andrew Kozin
@nepalez

One more thing provided by @marshall-lee for initializer in our commercial project is the ar_param or ar_option.
It allows to set object dependency as either model or model id.

In Rails projects this proves to be very suitable (example below is over-simplified):

class DestroyUser
  ar_param :user

  def call
    user.destroy
  end

  def self.call(*args)
    new(*args).call
  end
end

user_id = 1
user = User.find 1

# This methods are the same
DestroyUser.call user_id
DestroyUser.call user

Under the hood the method either gets an activerecord instance or finds its by id (or by another argument):

ar_param :user, find_by: :key

The question is what do you think about implementing this behaviour in a submodule of dry-initializer (dry-initializer/rails)?

Andy Holland
@AMHOL
@nepalez wouldn't want something specifically targeting rails in a dry core gem, but I don't see any harm to add it as an external plugin, perhaps dry-initializer could benefit for some kind of plugin system anyway (assuming it doesn't have one already)
Andrew Kozin
@nepalez
@AMHOL well, for one feature I'd say plugin system to be an overkill, but maybe you're right
Andy Holland
@AMHOL
I think it makes sense to make it extendible, if there's this use case there will be more
Nikita Shilnikov
@flash-gordon
guys, I raised an issue about replacing kleisli with something else. Any thoughts are very welcome dry-rb/dry-types#80 :)
Tim Riley
@timriley
@nepalez yeah, I think explicit support of AR is outside of dry-rb's mission. So having another gem to add these methods in would seem better to me.
@flash-gordon I feel generally in favor of this. Will comment on the GH issue later on :)