These are chat archives for dry-rb/chat

11th
Jul 2016
John Backus
@backus
Jul 11 2016 04:46
Am I doing something wrong here?
require 'bundler/setup'

gem 'dry-validation', '~> 0.9.0'

require 'dry/validation'
require 'dry/validation/version'

Dry::Validation::VERSION # => 0.9.0

SCHEMA =
  Dry::Validation.Schema do
    required(:bar).maybe(:str?)

    rule(conditional_foo: %i[foo bar]) do |foo, bar|
      foo.size?(9) | bar.str?
    end
  end

SCHEMA.call(foo: '123456789', bar: nil).messages # => {}
SCHEMA.call(foo: '12345678', bar: nil).messages  # => {}
SCHEMA.call(foo: nil, bar: nil).messages         # => {}
John Backus
@backus
Jul 11 2016 06:02
ah got it working by doing this:
SCHEMA =
  Dry::Validation.Schema do
    required(:foo).maybe(:str?)
    required(:bar).maybe(:str?)

    rule(conditional_foo: %i[foo bar]) do |foo, bar|
      (foo.str? & foo.size?(9)) | bar.str?
    end
  end
Piotr Solnica
@solnic
Jul 11 2016 09:53
@backus pls report an issue, would be nice to raise an arg error when you try to do foo.str? when there’s no “base” rule for :foo
Piotr Solnica
@solnic
Jul 11 2016 12:30
@/all Hey folks! We’ve set up a discussion forum for dry-rb organization. Please sign up here and let us know how you’d like to see it organized. I would also like to ask you kindly to post any support issues on the forum rather than this channel. Over the last few months dry-rb has grown very quickly and it’s simply impossible to keep up with both development-related discussions here and support requests. Thank you :smile:
Nikita Shilnikov
@flash-gordon
Jul 11 2016 18:08
@solnic dry-v now uses i18n by default but doesn't have it in gemspec dependencies. I updated dry-v and it fails with cannot load such file -- i18n Should I open an issue? At least we should kindly ask the user to install i18n
Piotr Solnica
@solnic
Jul 11 2016 18:15
That's a bug. It should not use i18n by default and it should not even require messages::i18n backend. No idea how this ended up like that
John Backus
@backus
Jul 11 2016 18:17
I had the pleasure of porting a lot of old model code to dry-validation this weekend
It is incredible how much more powerful dry-validation is
Piotr Solnica
@solnic
Jul 11 2016 18:18
@backus hah! fantastic
John Backus
@backus
Jul 11 2016 18:18
I'm very happy with the gem @solnic :)
Piotr Solnica
@solnic
Jul 11 2016 18:18
we’re just getting started :D
what’s your use case for it?
something less standard?
John Backus
@backus
Jul 11 2016 18:19
Heh sorry meeting now. I'll fill you in on the use case later
Piotr Solnica
@solnic
Jul 11 2016 18:19
no worries, ttyl
@flash-gordon uhm, dear lord…:(
I gotta add a spec for default behavior in settings…
I’ll fix it and push 0.9.1
after 1.0.0 I’ll be more careful and send PR for reviews, I promise ;)
Nikita Shilnikov
@flash-gordon
Jul 11 2016 18:21
cool :)
Piotr Solnica
@solnic
Jul 11 2016 18:21
we should lazy-require specific engines
Piotr Solnica
@solnic
Jul 11 2016 19:02
@flash-gordon fixed on master, pushing 0.9.1 once build is green
Nikita Shilnikov
@flash-gordon
Jul 11 2016 19:06
@solnic no hurry, I installed i18n
:D
Piotr Solnica
@solnic
Jul 11 2016 19:22
Successfully registered gem: dry-validation (0.9.1)
Deleting left over gem file dry-validation-0.9.1.gem
All is good, thanks my friend.
there you go
Maciej Mensfeld
@mensfeld
Jul 11 2016 20:25
@solnic not again xD
I don't have that much time to upgrade again :P
plz stap :D
Piotr Solnica
@solnic
Jul 11 2016 20:26
I just stopped ;P
moving to rom-rb :)
Maciej Mensfeld
@mensfeld
Jul 11 2016 20:26
eh - do you have a changelog somewhere for that release?
thanks ;)
nice changes solnic - nice
I really appreciate your contribution and I owe you more than 1 beer ;)
ping me once you're in Krakow
Piotr Solnica
@solnic
Jul 11 2016 20:35
haha will do
Joe Van Dyk
@joevandyk
Jul 11 2016 21:04
@solnic when are you planning on porting dry-validation to elixir? ;)
Piotr Solnica
@solnic
Jul 11 2016 21:12
@joevandyk soon
Joe Van Dyk
@joevandyk
Jul 11 2016 21:13
seriously?
Piotr Solnica
@solnic
Jul 11 2016 21:13
Yes
Joe Van Dyk
@joevandyk
Jul 11 2016 21:13
:heart:
is that your next language of choice?
Piotr Solnica
@solnic
Jul 11 2016 21:14
No idea :) I'm into Scala/Clojure/Elixir/Haskell :laughing:
John Backus
@backus
Jul 11 2016 21:19

@solnic responding to:

what’s your use case for it?
something less standard?

It was an api client we use internally which performs a bunch of specific business rule validations

My favorite was a ~70 LoC ActiveModel validator which I reduced down to a 3 line dry-v definition :)
Could be a one liner
but it would be a complex line
Piotr Solnica
@solnic
Jul 11 2016 21:24
Hah yeah! I started working on dry-v immediately after finishing a rails project where I had to write the most complex AM:V based validators ever (probably ;))
John Backus
@backus
Jul 11 2016 21:25
yup
Piotr Solnica
@solnic
Jul 11 2016 21:25
So basically all the features I wanted to have are based on all the things I was missing there
John Backus
@backus
Jul 11 2016 21:25
its funny reflecting on this validator now
The public method of the validation is just crying out for dry-v!
def check
  check_type && check_length && check_format
end
Piotr Solnica
@solnic
Jul 11 2016 21:26
:) maybe you could blog about it
Marketing and stuff. You know ;)
John Backus
@backus
Jul 11 2016 21:26
:) not a bad idea
Piotr Solnica
@solnic
Jul 11 2016 21:32
@backus may I OH that part about 70loc on twitter?
John Backus
@backus
Jul 11 2016 21:33
Yeah go for it
Can quote me. I'm @backus on Twitter
Piotr Solnica
@solnic
Jul 11 2016 21:36
Oh noez too late ;(
John Backus
@backus
Jul 11 2016 21:36
heh np
Piotr Solnica
@solnic
Jul 11 2016 21:36
Also, I know, I follow you :)
John Backus
@backus
Jul 11 2016 21:39
Fair enough :P
I'd love to see Transproc and dry-v benchmarks
Might be worth joining the concurrent ruby channel and seeing if Chris Seaton is interested in working on something with us
Piotr Solnica
@solnic
Jul 11 2016 23:24
@AMHOL fwiw dry-v is faster on jruby comparing to AM::V
as in, dry-v is more faster than AM::V on jruby than on mri
Andy Holland
@AMHOL
Jul 11 2016 23:44
lol that's a mouthfull