These are chat archives for dry-rb/chat

28th
Apr 2016
Luca Guidi
@jodosha
Apr 28 2016 07:54
Good morning all! Still writing tests for hanami-v and trying to cover all the possible combinations between macros. Does it makes sense to test required with: 1. value, 2. filled, 3 maybe? Should the last one not to be used in combination with required?
Similar question for optional, I'm testing it against the three modifiers above. Does it makes sense to use it with filled? Eg. optional(:foo).filled(...). Thanks! :)
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 28 2016 08:37
optional.filled? sounds reasonable: The respective key might or might not be present, but if it is present then the value must be filled
Benjamin Klotz
@tak1n
Apr 28 2016 08:37
good morning @jodosha
for your last example it makes absolutely sense to me, saying the key is optional but if its there the value must be filled
oops too late :D
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 28 2016 08:38
lol :D
even optional.maybe? sounds reasonable
for minimal restriction
Benjamin Klotz
@tak1n
Apr 28 2016 08:40
not sure what value is, its the new dsl syntax?
Luca Guidi
@jodosha
Apr 28 2016 08:46
@cdennl @tak1n Thank you folks! So should I test all the 6 combinations? required(:foo).value, required(:foo).filled, required(:foo).maybe, optional(:foo).filled, optional(:foo).value and optional(:foo).maybe?
@tak1n yes value is new dsl
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 28 2016 08:47
yes all combinations are viable
Benjamin Klotz
@tak1n
Apr 28 2016 08:47
@jodosha I would say yes
Luca Guidi
@jodosha
Apr 28 2016 08:50
@cdennl I'm only wondering if some combinations don't makes sense, but they aren't just restricted from the DSL.
@cdennl For instance what's the meaning of optional(:foo).filled?
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 28 2016 08:51
itm eans that the key can be present
Luca Guidi
@jodosha
Apr 28 2016 08:51
One one hand we say that it's optional, but on the other side we ask it to be filled? :sweat_smile:
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 28 2016 08:51
or not
but if it is present the value must be filled
you have to distinguish
between key and value
{} is valid
{key: nil} not
{key: 'value'} is valid
this is optional(:key).filled?
Luca Guidi
@jodosha
Apr 28 2016 08:53
Ok, so that is to overcome Ruby fallacies with Hashes? Is it similar to Hash#[] and Hash#fetch?
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 28 2016 08:54
well i use it in context with forms for instance
when you set and input to disabled
the key is not sent at all
for example if you disable a complete fieldset
then the keys if it or not sent
*of it
but if it is enabled you may want those sent values to be filled
Luca Guidi
@jodosha
Apr 28 2016 08:56
@cdennl That makes sense, it's just the naming that was puzzling me. On the other hand I can't suggest a solution right now.
@cdennl Thank you very much!
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 28 2016 08:58
but i dont now how some of these have changed with the new dsl
or is it already new dsl?
so in new dsl they might have another semantic
Piotr Solnica
@solnic
Apr 28 2016 09:04
@jodosha right-side defines rules for the key, left side defines rules for the value under that key. optional key means "it's valid when key is not present, otherwise check its value". in terms of logic, it's an implication so "presence of a key implies that its value must pass these rules, otherwise it's true"
Luca Guidi
@jodosha
Apr 28 2016 09:04
@solnic Thank you!
Piotr Solnica
@solnic
Apr 28 2016 09:04
so it boils down to dry-logic predicate composition: key?(:foo).then(value(:foo).filled?)
I understand this might confuse people since there's no other lib that allows you to be so specific, but it's a super handy feature and you can define entire data structure with precision including optional keys. We have use cases for that already like a user form where you may, or may not have password fields.
btw we shouldn't allow value w/o args I think, it does nothing
this should raise an arg error I believe
@coop wdyt ^?
Benjamin Klotz
@tak1n
Apr 28 2016 09:30
@solnic what exactly does value do?
you can apply predicates to the value? eg.: .value(max_size?: 50)
with .filled?(max_size?: 50) you can do that too but filled also checks first that the value is not nil
Benjamin Klotz
@tak1n
Apr 28 2016 09:35
so basically
.value(max_size?: 50) expands to { max_size?(50) }
and
.filled(max_size?: 50) expands to { filled? & max_size?(50) }
Piotr Solnica
@solnic
Apr 28 2016 09:36
@tak1n yes
Benjamin Klotz
@tak1n
Apr 28 2016 09:36
@solnic cool thx :)
Piotr Solnica
@solnic
Apr 28 2016 09:36
it's a macro for uber-common case of non-emptyness
there's caveat though, filled? works with a couple of types, so you better add a type expectation too
Benjamin Klotz
@tak1n
Apr 28 2016 09:38
okay thx for clearing it up :)
Piotr Solnica
@solnic
Apr 28 2016 09:39
@jodosha if you want you could push a wip pr with what you have with dry-v and we can take a look
in rom/dry we often open PRs quite early and collaborate
Luca Guidi
@jodosha
Apr 28 2016 11:31
@solnic I'm trying to make the tests to pass with new h-v DSL + master of dry-v. Unfortunately my OSS time is limited. I'll ping you once ready.
@solnic Thanks, btw! :D
panigrah
@panigrah
Apr 28 2016 12:05

@iBublik did you get your custom message working?
a) are you using i18 for messages? - I had trouble with i18 so I switched the format to yaml with option.messages = :yaml
b) where are you storing the custom messages? - I overrode the default location with option.message_file=path_to_message_file
b) are you sure the error message file is being loaded?

The name spacing did not matter in my case - I put it directly under errors.

Artem Pyankov
@iBublik
Apr 28 2016 12:07
@panigrah I've reported issue dry-rb/dry-validation#116 . I'm using i18n and everything is fine, but it 's not working only for key? predicate. As @solnic said it's expected behavior for now
panigrah
@panigrah
Apr 28 2016 12:12
thanks - that is good to know. I may have ended up butting my head against the same thing shortly
Joe Van Dyk
@joevandyk
Apr 28 2016 23:14
is dry-validation usable in a rails project yet?
Andy Holland
@AMHOL
Apr 28 2016 23:31
Should be, not sure whether dry-types will cause problems if you want to use form schemas
Joe Van Dyk
@joevandyk
Apr 28 2016 23:53
my use case is validating json