These are chat archives for dry-rb/chat

29th
Apr 2016
Joe Van Dyk
@joevandyk
Apr 29 2016 00:52
Anyone know if rails works with the types? Don't need autoloading really
Andy Holland
@AMHOL
Apr 29 2016 01:01
@joevandyk it works, it's code reloading in dev env that causes the problems
Joe Van Dyk
@joevandyk
Apr 29 2016 01:04
Problems as in reloading doesn't work? Or rails+dry-* will cause rails in Dev mode to not work?
Guess I should try :)
Andy Holland
@AMHOL
Apr 29 2016 01:13
dry-types will cause exceptions with reloading as it tries to register the types on each reload
Nicolas Cavigneaux
@Bounga
Apr 29 2016 15:35
Hi there, seems like I wan't use variables in regexp provided to format? predicate
Is it a bug of dry-v or me?
let say I have something like:
var = "foo"
key(:number);required(format?: /^D#{var}/)
Nicolas Cavigneaux
@Bounga
Apr 29 2016 15:40
it will fail with something like
RegexpError: premature end of char-class: /^D0[:check, [:zipcode, [:predicate, [:[], [0, 2]]], [:zipcode]]]/
    from /Users/nico/Synbioz/Code/ffepgv/ffepgv-core/lib/ffepgv/core/entities/entity.rb:50:in `block (2 levels) in schema'
    from /Users/nico/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/dry-validation-0.7.4/lib/dry/validation/schema/value.rb:75:in `instance_exec'
    from /Users/nico/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/dry-validation-0.7.4/lib/dry/validation/schema/value.rb:75:in `rule'
I thought it would work the same way "normal" regexp in ruby does
Nicolas Cavigneaux
@Bounga
Apr 29 2016 15:56
Think I understood
not a bug sorry
Is there any way to access an attribute of the object from within a rule ?
Nicolas Cavigneaux
@Bounga
Apr 29 2016 16:28
What I'm trying to do is to create a rule verifying that if the value of the attribute foo is "123", then the attribute bar value must be D123
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 29 2016 16:34
@Bounga You want to write a custom predicate if it is dependent only on one value otherwise you need a highlevel rule
but it sounds like you a re dependent on foo and bar
so you need to write a highlevel rule
Piotr Solnica
@solnic
Apr 29 2016 16:38
@Bounga rule(something: [:foo, :bar]) { |foo, bar| bar.some_custom_predicate?(foo) } and def some_custom_predicate?(x, y); y == "D#{x}"; end
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 29 2016 16:39
almost @solnic one y must be x :)
Piotr Solnica
@solnic
Apr 29 2016 16:39
there ;)
Christopher Dennl-Ortega Arrieta
@cdennl
Apr 29 2016 16:40
;P
Nicolas Cavigneaux
@Bounga
Apr 29 2016 20:30
@solnic @cdennl Thank you I'll try this
Nicolas Cavigneaux
@Bounga
Apr 29 2016 21:11
It's working great thank you
is there a way to add messages to existing one? Or should I have to recreate a whole translation file when I add a new predicate?
Piotr Solnica
@solnic
Apr 29 2016 21:37
@Bounga r u using i18n?