These are chat archives for dry-rb/chat

4th
Feb 2016
Fran Worley
@fran-worley
Feb 04 2016 09:39

@solnic progress looks great, any ideas on what's causing this reform issue when using dry-validation from master?

TypeError: can't convert Dry::Validation::Schema::Rule::Result to Integer (Dry::Validation::Schema::Rule::Result#to_int gives Dry::Validation::Schema::Rule::Result)

It was working fine on 0.6...

Fran Worley
@fran-worley
Feb 04 2016 09:54
Ignore me, I was being an idiot. All sorted.
Fran Worley
@fran-worley
Feb 04 2016 10:12

@solnic is there a way to actually get the value of another key?
Ideally I want to be able to do something like:

value(:lockable_method).inclusion?(Lockable.lockable_methods[value(:lockable_type).underscore.to_sym])

If I define this as a custom predicate, I can make use of reforms 'form' variable to get the value but I can't find a way to include my inclusion array in the custom error message...

Piotr Solnica
@solnic
Feb 04 2016 11:25
@fran-worley that’s not gonna be supported yet
and value(:foo).underscore will never work, since the dsl is “virtual"
you need a custom predicate for this kind of stuff
Fran Worley
@fran-worley
Feb 04 2016 11:33
nope thats fine, I just wondered if there was a way to actually get the value for another key
value(:foo).value or something
Piotr Solnica
@solnic
Feb 04 2016 11:36
@fran-worley value(:foo) will be evaluated to a value but the dsl is virtual, it only generates an ast so that we can generate rules
btw passing additional data to messages will be possible, but it’s not supported yet
Fran Worley
@fran-worley
Feb 04 2016 11:39

@solnic ah ok thats fine, if I can pass additional data to messages then the custom predicate is no issue. I'm doing this currently:

key(:lockable_method){ |value| value.valid_method? }

def valid_method?(value)
  methods = Lockable.lockable_methods[form.lockable_type.underscore.to_sym].concat(["",nil])
  methods.include?(value)
end

It works fine its just my error message isn't particularly helpful...

Piotr Solnica
@solnic
Feb 04 2016 11:40
yeah I know, I’ve been aware of this limitation since day 1 and it was always on my todo list, but first things first, as they say
I’m doing another round of refactoring now, dry-logic was simplified significantly but now I gotta update dry-v to work with it, it’s gonna be a substantial simplification, I hope it’s the last round now haha
Fran Worley
@fran-worley
Feb 04 2016 11:41
Obviously, no worries I'm using this code in a private engine so an improved message would just make the perfectionist inside me happy :smile:
Piotr Solnica
@solnic
Feb 04 2016 11:42
my inner perfectionist ^5s your inner perfectionist
Fran Worley
@fran-worley
Feb 04 2016 11:43
:star2: Your hard work is much appreciated. When your refactorings have slowed down I'd love to help update the docs. There is no reference to the new macros/ DSL and not everyone is going to trawl though this gitter thread...
Piotr Solnica
@solnic
Feb 04 2016 11:44
of course, thank you!
Fran Worley
@fran-worley
Feb 04 2016 11:45
I'll take a look once 0.7 is out. I'll probably create an example app to illustrate it working.
Piotr Solnica
@solnic
Feb 04 2016 17:43
seems like it’s gonna take longer than I thought, need roughly a week or so still :/ /cc @fran-worley
Fran Worley
@fran-worley
Feb 04 2016 17:44
@solnic no worries, take your time :smiley: