These are chat archives for dry-rb/chat

27th
May 2016
John Backus
@backus
May 27 2016 00:33
Thanks @solnic. I wasn't actually doing required(:data) by itself, I just try to reduce my bug examples down to the smallest amount of code needed to reproduce possible
with that said: noted :)
Joe Van Dyk
@joevandyk
May 27 2016 03:03
Is dry-transaction going to use dry-monad?
Alexander Gräfe
@rickenharp
May 27 2016 05:38
@joevandyk master already does: dry-rb/dry-transaction@c951710
Tim Riley
@timriley
May 27 2016 09:57
@joevandyk I'll release that this coming week too
Maciej Mensfeld
@mensfeld
May 27 2016 10:37
@solnic I wonder about one thing - I'm building a multistep processor that is populating step by step a schema using data provided by previous steps (sounds like a place for monads ;) ) - is there a way to do that using dry-types and/or dry-validation? I mean I can't create immutable object since in next steps some of its values are added based on some calcuations. I could create a new instance further on and replace the previous one but validation will stop me. Any idea how to solve a multi step builders problem?
Piotr Solnica
@solnic
May 27 2016 10:42
@mensfeld not supported yet by existing APIs
Maciej Mensfeld
@mensfeld
May 27 2016 10:42
@solnic any plans for that?
Piotr Solnica
@solnic
May 27 2016 10:42
yep
prior 1.0
Maciej Mensfeld
@mensfeld
May 27 2016 10:42
ok ;) then I will just bypass the problem for now and migrate later ;)
Piotr Solnica
@solnic
May 27 2016 10:42
possibly in 0.9.0
a simplified scenario reported as an issue would help btw
Maciej Mensfeld
@mensfeld
May 27 2016 10:44
still dry-validation and dry-types - great idea especially when bui0ding apps that rely on internal gems/data sources - I can just define an expected schema that everyone needs to follow without exceptions
no bypassing, etc :) <3
Piotr Solnica
@solnic
May 27 2016 10:46
yeah, this is type safety, removes heaps of complexity from code
you can safely work with data w/o being worried that things will blow up
Maciej Mensfeld
@mensfeld
May 27 2016 10:56
Once I handle my case - I will try to make a usable example
The only way how I see that it could work now is to create a schema from which I will take data (using output) and replacing it until I reach the "final" state
@solnic is there a way to revalidate a result?
Piotr Solnica
@solnic
May 27 2016 11:01
wdym?
Maciej Mensfeld
@mensfeld
May 27 2016 11:02
example
schema.call({})
data = schema.result
data.merge!(new_attribute: 2)
scheme.validate!
@solnic nvmd - I can just reschema this
stupid me
Piotr Solnica
@solnic
May 27 2016 11:04
don’t mutate :P
Maciej Mensfeld
@mensfeld
May 27 2016 11:05
;) heheheh I know :P
Maciej Mensfeld
@mensfeld
May 27 2016 11:18
@solnic how can I say that I want a key that gets a schema but optionally? I mean will something like that work:
key(:lol).maybe.schema(OtherSchema)
I mean it is optional but if it is, it needs to fit into this schema
Piotr Solnica
@solnic
May 27 2016 11:20
not supported yet, I’ll add support for blocks to macros in 0.8.0
so required(:lol).maybe { schema(OtherSchema) }
for now you could do this I think:
Maciej Mensfeld
@mensfeld
May 27 2016 11:21
ok - thanks :)
Piotr Solnica
@solnic
May 27 2016 11:21
key(:lol) { none? | schema(OtherSchema) }
Maciej Mensfeld
@mensfeld
May 27 2016 11:21
ok :) enough for me
Btw this is a good case - first I wanted to use dry-types but it seems that it is way better (when you build multistep results) to use dry-validations and validate at the ends, insted of step by step as I can describe the data much better
There was a really interesting talk about dry-gems @ SRUG few days ago btw :)
Maciej Mensfeld
@mensfeld
May 27 2016 11:28
@solnic sorry for so many questions but I cant figure that out based on the docs - how can I reuse a schema to validate elements in the array?
will that work?
key(:offenses).each { schema Engine::Result::Offense }
Piotr Solnica
@solnic
May 27 2016 11:33
it should yea
try key(:offenses).each(Engine::Result::Offense) too
Maciej Mensfeld
@mensfeld
May 27 2016 11:34
ok - thx!
Tim Riley
@timriley
May 27 2016 11:51
@mensfeld cool to hear someone is talking about it! Where's SRUG?
Maciej Mensfeld
@mensfeld
May 27 2016 11:52
@timriley Silesian Ruby User Group - Gliwice, Poland
Andy Holland
@AMHOL
May 27 2016 11:53
@solnic that's only an hours drive from you
:D
Piotr Solnica
@solnic
May 27 2016 11:54
@AMHOL huh?
aah, SRUG, yeah BUT NOBODY INVITED ME ;)
Andy Holland
@AMHOL
May 27 2016 11:54
lol
Maciej Mensfeld
@mensfeld
May 27 2016 11:54
@solnic you can invite yourself :P it is a potem meetup group ;)
solnic @solnic feels unloved
Piotr Solnica
@solnic
May 27 2016 11:55
anyhow, what’s happing in SRUG?
Maciej Mensfeld
@mensfeld
May 27 2016 11:55
@solnic wdym? :D
just bunch of people talking about ruby :D
Piotr Solnica
@solnic
May 27 2016 11:56
but Tim mentioned that somebody is talking about “it”
what is it?
Maciej Mensfeld
@mensfeld
May 27 2016 11:56
yes someone indeed had a talk about dry-gems
Andy Holland
@AMHOL
May 27 2016 11:57
Selection_050.png
Selection_051.png
@solnic ^
Piotr Solnica
@solnic
May 27 2016 11:59
@mensfeld was it recorded? any slides?
Maciej Mensfeld
@mensfeld
May 27 2016 12:00
@solnic no idea - you can ask here: http://www.meetup.com/srugpl/events/230669647/
Hannes Nevalainen
@kwando
May 27 2016 12:02
Can I get the "value" that is being validated in a high level rule? I have a schema which accepts 2 IDs and I need to do a DB lookup to verify them.
Andy Holland
@AMHOL
May 27 2016 12:03
@solnic just saw rom-rb/rom-rb.org#121
Piotr Solnica
@solnic
May 27 2016 12:03
@kwando wdym? it’s passed to the predicate as args
@AMHOL you mean the issue or the talk?
Andy Holland
@AMHOL
May 27 2016 12:04
Watching the talk now
But I can't help but think of https://www.youtube.com/watch?v=xrIjfIjssLE every time someone mentions Joe Armstrong now
:laughing:
Hannes Nevalainen
@kwando
May 27 2016 12:05
@solnic let me gist an example
Piotr Solnica
@solnic
May 27 2016 12:05
@AMHOL lol rite
Andy Holland
@AMHOL
May 27 2016 12:07
Hello Joe, Hello Mike :joy:
@solnic
^^
just made an simplified example up
Piotr Solnica
@solnic
May 27 2016 12:13
busy atm, will look later
Hannes Nevalainen
@kwando
May 27 2016 12:13
@solnic sure, no hurry =)
Maciej Mensfeld
@mensfeld
May 27 2016 12:38
@solnic - how can I do an enum with dry-validations?
fuck inclusion
nvmd
Piotr Solnica
@solnic
May 27 2016 13:01
let’s not drop F bombs w/o a good reason please :)
Maciej Mensfeld
@mensfeld
May 27 2016 13:02
sorry :(
Piotr Solnica
@solnic
May 27 2016 13:03
no worries :)
I don’t mind, I swear like hell, just not here :D
Maciej Mensfeld
@mensfeld
May 27 2016 13:04
@solnic is there a way to bang the schema validaion? I mean something likecall! - I need to raise an error anytime anything is invalid
Piotr Solnica
@solnic
May 27 2016 13:06
just do it yourself
invalid data is not an exception from dry-v pov’s
Maciej Mensfeld
@mensfeld
May 27 2016 13:06
thx
Maciej Mensfeld
@mensfeld
May 27 2016 13:18
@solnic - tis wont work key(:offenses).each(Engine::Result::Offense)
and I have one more (last) issue - array keys with each of a subschema
key(:authors).each { none? | schema(Author) } won't work
  • the second one works - I did a typo (nil? / none?) but the first one wirks only when passed as a block
I've spotted one more thing = I have something like that:
key(:authors).maybe.each { schema(Author) }
and even if stated as maybe - it still validates when not presend
Piotr Solnica
@solnic
May 27 2016 13:25
@mensfeld ok then key(:authors) { none? | each { schema(Author) } }
Maciej Mensfeld
@mensfeld
May 27 2016 13:30
@solnic checking
@solnic ArgumentError: +each+ is not a valid predicate name
Piotr Solnica
@solnic
May 27 2016 13:33
¯\_(ツ)_/¯
Maciej Mensfeld
@mensfeld
May 27 2016 13:33
I need to do somethng like that: key(:authors).each { empty? | schema(Author) }
and then I can just add an empty array
still need to pass the array but maybe that's even better
Piotr Solnica
@solnic
May 27 2016 13:33
it’ll be working in next version
Maciej Mensfeld
@mensfeld
May 27 2016 13:34
:D
Maciej Mensfeld
@mensfeld
May 27 2016 13:39
Now it looks awesome!
module Enjin
  module Schema
    Result = Dry::Validation.Schema(Base) do
      key(:raw).required { schema(Raw) }
      key(:metadata).required { schema(Metadata) }
      key(:performance).required { schema(Performance) }
      key(:authors).each { empty? | schema(Author) }
      key(:offenses).each { schema(Offense) }
    end
  end
end
Eduardo de Oliveira Hernandes
@eduardodeoh
May 27 2016 13:42
@solnic Thank you so much, i will try this code and back to you later, ok.
Piotr Solnica
@solnic
May 27 2016 13:44
@mensfeld :muscle:
Ralf Schmitz Bongiolo
@mrbongiolo
May 27 2016 14:23
@kwando I guess you could try something like this:
new_post_schema = Dry::Validation.Schema{
  configure do
    def belongs_to?(author_id, category_id)
      Author.find(author_id).categories.exists(category_id)
    end
  end

  key(:author_id).required(:int?)
  key(:category_id).required(:int?)

  key(:title).required(:str?)
  key(:body).required(:str?)

  rule(belongs_to_author: [:category_id, :author_id]) do |category_id, author_id|
    category_id.belongs_to?(author_id)
  end
}
maybe it would be better to pass the user using with() on the initialization, if you already know him
Hannes Nevalainen
@kwando
May 27 2016 14:37
@mrbongiolo <3
didn't know you could that
Ralf Schmitz Bongiolo
@mrbongiolo
May 27 2016 14:38
I'm not sure if this is the best or correct way to do it, but I needed something similar and got it to work like that...
Don Morrison
@elskwid
May 27 2016 14:48
@solnic we’re going to be working on internal work to use dry-v for our strong params work to share the definitions between the rails controllers and the Grape API (legacy app)
Perhaps that will provide some fodder for a gem...
Hannes Nevalainen
@kwando
May 27 2016 14:49
@mrbongiolo it works for now =)
Andy Holland
@AMHOL
May 27 2016 15:02
@solnic 4 replies to that tweet
Tomek Rusiłko
@rusilko_twitter
May 27 2016 16:52
This message was deleted
Tomek Rusiłko
@rusilko
May 27 2016 16:56
Hi all, just checking in and exploring gitter :)
Piotr Solnica
@solnic
May 27 2016 17:04
@rusilko welcome :wave:
Martin Häusler
@nightcoding
May 27 2016 17:18
hi there 👋🏼
Chase Gilliam
@Ch4s3
May 27 2016 17:21
so what's needed to get started on dry-validation-rails @solnic
Piotr Solnica
@solnic
May 27 2016 17:28
@nightcoding hello :)
so first of all thanks for your interesting in helping out
Chase Gilliam
@Ch4s3
May 27 2016 17:29
:+1:
Piotr Solnica
@solnic
May 27 2016 17:29
as you probably know I’m no longer working on anything rails-related hence I asked for help
Chase Gilliam
@Ch4s3
May 27 2016 17:29
right
Piotr Solnica
@solnic
May 27 2016 17:30
so I was thinking about adding a railtie that would set up dry-v so it’s a smooth experience for a rails developer and then have some additional API in the controllers that would allow using dry-v instead of strong params
strong-params is a) limited b) slow that’s why it felt like a good idea
to use dry-v instead
defining schemas in the controllers would be too messy I think, so we could have some simpler and more concise API that would set up validation schemas behind the scenes and cache them (rebuilding schemas on each request makes no sense)
we could a lot of things here, ie derive schemas from AR models etc
Martin Häusler
@nightcoding
May 27 2016 17:35
i really like your idea of dry-v (btw I don't like strong_params, too!). As I am not so experienced in creating gems / extensions I would need some advise by implementing the features.
Piotr Solnica
@solnic
May 27 2016 17:37
maybe you guys could work on this together then? :)
Martin Häusler
@nightcoding
May 27 2016 17:40
i hope so 😁
Joe Van Dyk
@joevandyk
May 27 2016 17:54
in an integration test where i want to replace a Container’s action(? method?) with a spy, what’s the best way to do that?
basically temporarily register the container with a new thing
Piotr Solnica
@solnic
May 27 2016 18:07
@joevandyk not sure if that’s released already but there’s an api for stubbing
Tomek Rusiłko
@rusilko
May 27 2016 18:20
Guys, I am on the run right now so I'll share my thoughts on this later. In general I don't have much experience in oss but I am all in for doing this and learning along the way. :)
Joe Van Dyk
@joevandyk
May 27 2016 18:21
@solnic hm, i tried using master and doing Container.enable_stubs! but it’s saying enable_stubs! not defined
ah, i guess i need require 'dry/container/stub'
Joe Van Dyk
@joevandyk
May 27 2016 18:27
getting an error saying already registered:
    before do
      Container.enable_stubs!
      Container.register('tanga_api', -> { api_spy })
    end
    after do
      Container.unstub
    end
gah
need to use stub
not my morning
Joe Van Dyk
@joevandyk
May 27 2016 18:34
@solnic beautiful, thanks!
Ralf Schmitz Bongiolo
@mrbongiolo
May 27 2016 18:34
@solnic when defining a high level rule like: rule(should_be_on_same_date: [:date, :another_date]) { |date, another_date| ... } it seems like the name of the rule should_be_on_same_date is not used to generate a message. Shouldn't I be able to just add on my YML file this?:
en:
  errors:
    rules:
      should_be_on_same_date: 'message here'
Or the rule name is there just to know what that rule is doing when reading a schema?
Piotr Solnica
@solnic
May 27 2016 18:35
try en.errors.should_be_on_same_date
IIRC it’s a known issue, I messed up look up path
sorry about that, I was away for the last 4 weeks not doing any coding so we’ve got 10 known bugs that haven’t been fixed yet
Ralf Schmitz Bongiolo
@mrbongiolo
May 27 2016 18:36
I just tried that and it worked, but thanks for the tip :)
but when corrected it will go under error: rules:right?
Piotr Solnica
@solnic
May 27 2016 18:37
I think that’s how it should be done, people are tripping on it
Ralf Schmitz Bongiolo
@mrbongiolo
May 27 2016 18:38
well, it makes sense to be under rules, since we have that key on the messages files...
Piotr Solnica
@solnic
May 27 2016 19:03
yep