Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 08:07
    btir starred dry-rb/dry-types
  • 08:07
    btir starred dry-rb/dry-monads
  • 01:05
    krmannix starred dry-rb/dry-initializer
  • Jan 17 19:43

    dry-bot on master

    [devtools] update CHANGELOG.md (compare)

  • Jan 17 19:42

    flash-gordon on master

    Update changelog.yml (compare)

  • Jan 17 19:41

    flash-gordon on master

    Update changelog.yml (compare)

  • Jan 17 19:36

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 17 19:36

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 17 19:36

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 17 19:36

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 17 19:36

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 17 19:36

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 17 19:36

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 17 19:36

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 17 19:36

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 17 19:35

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 17 18:39

    flash-gordon on master

    Update changelog.yml (compare)

  • Jan 17 18:25

    flash-gordon on alias-constructors

    (compare)

  • Jan 17 18:25

    flash-gordon on master

    Add aliases for .constructor T… Merge pull request #383 from dr… (compare)

  • Jan 17 18:25
    flash-gordon closed #383
Christopher Dennl-Ortega Arrieta
@cdennl
@solnic ok so in my errors.yml I only have to specify a string for the rule name then
Joshua Wilcox
@joshuaswilcox

So I tried

        required(:user_id).maybe(:int?)
        required(:global_auth_id).maybe(:str?)

        rule(valid_user: [:user_id, :global_auth_id]) do |user_id, global_auth_id|
          user_id.false?.then(global_auth_id.filled?)
        end

        rule(valid_auth_id: [:user_id, :global_auth_id]) do |user_id, global_auth_id|
          global_auth_id.false?.then(user_id.filled?)
        end

but i get

>> @schema.call(global_auth_id: '2')
=> #<Dry::Validation::Result output={:global_auth_id=>"2"} messages={:user_id=>["is missing"]}>
Christopher Dennl-Ortega Arrieta
@cdennl
@solnic ah it is optional? if it is not present it will use predicate?
Piotr Solnica
@solnic
when it’s missing we won’t apply any other rule
you marked it as required
Joshua Wilcox
@joshuaswilcox
so optional then?
with that I get
>> @schema.call(user_id: nil)
=> #<Dry::Validation::Result output={:user_id=>nil} messages={}>
basically I am trying to use two different params to do the same thing, so either is ok, but at least one and not both, ha
Christopher Dennl-Ortega Arrieta
@cdennl
@joshuaswilcox user_id.filled? xor global_auth_id.filled?
as one rule
Joshua Wilcox
@joshuaswilcox
same result
>> @schema.call(user_id: 1)
=> #<Dry::Validation::Result output={:user_id=>1} messages={:global_auth_id=>["is missing"]}>
>> @schema.call(global_auth_id: '1')
=> #<Dry::Validation::Result output={:global_auth_id=>"1"} messages={:user_id=>["is missing"]}>
>> @schema.call(global_auth_id: '1', user_id: nil)
=> #<Dry::Validation::Result output={:user_id=>nil, :global_auth_id=>"1"} messages={:user_id=>["must be filled"]}>
I think maybe I am approaching my problem the wrong way
Christopher Dennl-Ortega Arrieta
@cdennl
with both marked optional?
nah you don't i have the same sitations
with xor
Joshua Wilcox
@joshuaswilcox
yeah both optional
Christopher Dennl-Ortega Arrieta
@cdennl
its a common case
Joshua Wilcox
@joshuaswilcox
xor doesn't work for me either
Christopher Dennl-Ortega Arrieta
@cdennl
can you give me your code please the complete one
Joshua Wilcox
@joshuaswilcox
 @schema = Dry::Validation.Form do
        optional(:user_id).maybe(:int?)
        optional(:global_auth_id).maybe(:str?)

        rule(valid_user: [:user_id, :global_auth_id]) do |user_id, global_auth_id|
          user_id.filled? or global_auth_id.filled?
        end
      end
Christopher Dennl-Ortega Arrieta
@cdennl
xor
doesnt work?
or ^
Joshua Wilcox
@joshuaswilcox
ArgumentError: +xor+ is not a valid predicate name
Christopher Dennl-Ortega Arrieta
@cdennl
user_id.filled? ^ global_auth_id.filled?
or user_id.filled?.xor( global_auth_id.filled? )
Joshua Wilcox
@joshuaswilcox
yeah ^ worked
Thanks for the help!
Christopher Dennl-Ortega Arrieta
@cdennl
no problem, so the complete problem is solved?
another solution would have been: (user_id.filled? & global_id.none?) | (user_id.none? & global_id.filled?) that would be the xor expanded
Joshua Wilcox
@joshuaswilcox
ah good to know thanks! yeah problem solved from a validation point of view :)
Christopher Dennl-Ortega Arrieta
@cdennl
(and,or,not)x(true,false) defines a complete base of boolean logic, any predicate logic term can be assembled out from these three operations on true,flase
Piotr Solnica
@solnic
@cdennl make both keys optional if that’s your case
Christopher Dennl-Ortega Arrieta
@cdennl
@solnic I have no problem :) just tried to help joshua
Piotr Solnica
@solnic
oh sorry ok cool cool :)
Christopher Dennl-Ortega Arrieta
@cdennl
@solnic what I didnt get, ruley key for error message is optional or mandatory?
Piotr Solnica
@solnic
it’s needed when custom rule name was provided
Christopher Dennl-Ortega Arrieta
@cdennl
alright thanks
Joe Van Dyk
@joevandyk
@solnic no luck on setting config.type_specs = true
Form = Dry::Validation.Form do
end

FormContainer = Dry::Validation.Form do
  configure { config.type_specs = true }
  each { schema Form }
end
Christopher Dennl-Ortega Arrieta
@cdennl
@solnic is it possible to make a own section for rule messages in the error hash like so:
required( :param ).filled(:int?)

rule(check_special: [ :param ]) do |param|
  param.gt?(10)
end

errors should be something like: { param: ["must be filled"], rule: { check_special: ["must definitely be greater than 10 you moron"] } }
It would be nice to have a mechanism to know instantly whether a high-level rule generated the error or primitive statement
however this implies reserving a key in the errors hash
for now I am working around by using a name scheme for highlevel rules, but this feels not clean enough
Piotr Solnica
@solnic
please report issues describing what you need
this way it is easier to handle that
Christopher Dennl-Ortega Arrieta
@cdennl
ok will do that thanks
Christopher Dennl-Ortega Arrieta
@cdennl
@solnic Do I get it right, that validate is like rule, but passes in the actual values and the code block just return true or false?
Piotr Solnica
@solnic
@cdennl yes, it is like defining a predicate method that will be executed in the context of your schema, so its state is available there