These are chat archives for dry-rb/chat

1st
Jun 2016
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 01:32
:satisfied:
John Backus
@backus
Jun 01 2016 01:36
@timriley is that just a custom static image or is there a service that actually determines that?
I would love for that to become a thing. Could use this monkey patch detecting gem I wrote a while ago https://github.com/backus/monkey_catch
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 02:02
@solnic is the "model" Schema (using attr) already working for this version of dry-v?
Piotr Solnica
@solnic
Jun 01 2016 07:18
@mrbongiolo it was removed, we're looking for somebody who could bring it back in a separate gem
Nikita Shilnikov
@flash-gordon
Jun 01 2016 07:42
@timriley :+1: I knew there must be a service for it :)
Tim Riley
@timriley
Jun 01 2016 08:18
@flash-gordon @backus it's just a static image - I know I'll never need to change it here :joy:
Nikita Shilnikov
@flash-gordon
Jun 01 2016 08:23
I mean a service with badges :)
but I'll be watching you ;)
Piotr Solnica
@solnic
Jun 01 2016 08:26
are you saying we want to start a monkey-patch-shaming campaign? :P
John Backus
@backus
Jun 01 2016 08:30
I would love that
actual badges
its hard to know. Dependencies can introduces patches you didn't know about
See: Kleisli
Piotr Solnica
@solnic
Jun 01 2016 08:33
I would defo support this
can’t contribute, but big :+1:
won’t be a trivial thing to do :)
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:24
@solnic but it should be something similar to dry-v, but just focused on Struct/Objects?
Piotr Solnica
@solnic
Jun 01 2016 12:25
@mrbongiolo it’s gonna be re-introduced assuming somebody is willing to work on it
it is supported by dry-logic, we just removed that dsl-bits from dry-v
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:26
Ok
Piotr Solnica
@solnic
Jun 01 2016 12:26
with an intention of re-introducing it in a separate lib
dry-v-model or something dunno
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:26
why on a separate lib? Couldn't it just be another "Schema" type? like Form or Json?
Piotr Solnica
@solnic
Jun 01 2016 12:29
I think it’s gonna be an anti-pattern :P
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:29
hahaha
Piotr Solnica
@solnic
Jun 01 2016 12:29
mostly for people stuck with stateful dirty objects
if you need state and complex behaviors then sth like Reform should be better
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:29
Well, since I'm still on Rails OO land I'll need it
Piotr Solnica
@solnic
Jun 01 2016 12:29
or hanami-validation, I expect it to provide some high-level functionality too
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:30
uhm
But when you were using it, how you validated not parameters stuff? in a completely separated "step"?
Luca Guidi
@jodosha
Jun 01 2016 12:31
@mrbongiolo @solnic Which kind of high-level functionality?
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:32
@jodosha model validations, based on attributes probably, something like: attr(:status).eql? 'moving'
this is something that I have to check quite often, if the resource someone wants to update can actually be updated, right now I'm doing it outside a dry-v-schema
Luca Guidi
@jodosha
Jun 01 2016 12:34
@mrbongiolo We used to offer with stable versions of h-model and h-validations, but mutable state, indifferent access of internal data, and dirty tracking made that integration a really bad idea.
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:35
Yeah I guess it wouldn't be something "clean" to do
Luca Guidi
@jodosha
Jun 01 2016 12:35
@mrbongiolo Now we're gonna to remove all these bad ideas (mutable state etc..), but not sure if we want to support that integration again.
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:36
@jodosha it might be better like @solnic proposed then: a separated lib, just for models
Luca Guidi
@jodosha
Jun 01 2016 12:36

this is something that I have to check quite often, if the resource someone wants to update can actually be updated, right now I'm doing it outside a dry-v-schema

Do you have some example? Not sure I understood :D

Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:39
errors = {}
errors[:base] = [I18n.t('errors.messages.invalid_status')] unless resource.status == 'sent'
# other checks
unprocessable_entity!(errors) if errors.present?
I'm doing something like this right now, status is an attribute from the resource, not a parameter received from the user, and I can only modify the resource if it's on the correct status.
I have other more complex case in which I can only process a request if I have openings in a open Appointments, that are tracked in another model/resource, this for sure wouldn't be able to be put directly in a hashed Schema
but maybe it could be worked out as another lib that just deals with those dirty, mutable state objects
Luca Guidi
@jodosha
Jun 01 2016 12:44
@mrbongiolo I see. Until we don't shape h-model on top of ROM, that integration will be out of scope for a while. And it won't probably play well with AR (assuming that you're using it).
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:45
schema = Dry::Validation::ModelSchema do
  configure do

    def has_availalbe_appointments?(value)
      Appointment.available_appointments_for_period(value).any?
    end
  end

  attr(:status).eql? 'sent'
  attr(:period).has_available_appointments?
end

schema.call(@model).messages # => { status: ['is invalid'] }
something like this might be possible to achieve, but again, this should be done in different steps, first use the regular Schema, then if everything is ok check the model and other more complex validations.
Michał Pietrus
@blelump
Jun 01 2016 12:49
@mrbongiolo Hi! How does these data validation vs. model validation differ from the 'validation step' point of view? Isn't it just a validation step?
Luca Guidi
@jodosha
Jun 01 2016 12:49
@mrbongiolo @blelump indeed
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:53
@blelump but right now dry-v doesn't support model as input, and supporting it alongside a param input wouldn't be good, basically the model validation would be a schema type dedicated to handle models.
I'm referring to "step" as something from an operation or request point of view, instead of having a giant schema that can handle everything you (if needed) would first validate data input, then model state.
Piotr Solnica
@solnic
Jun 01 2016 12:56
I think this kind of separation is a good idea
I wouldn’t put too much stuff into schemas
we should see what makes most sense
Luca Guidi
@jodosha
Jun 01 2016 12:56
@mrbongiolo So it's not a matter of workflow as me and @blelump probably thought, but it's a matter of the schema being able to read data from getters instead from a Hash?
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 12:59
@jodosha correct, some workflows might not need it, but if you're using rails or something similar you might end up needing it.
Luca Guidi
@jodosha
Jun 01 2016 13:00
@mrbongiolo What about data serialization? eg: schema.call(model.attributes)
..On a different subject, @timriley @solnic Dunno if you use entr for dry-web, but beware of this: hanami/hanami#591
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 13:02
@jodosha I thought about it, it could work, but it wouldn't be good, I think it's better to have a separated entity just to deal with the model. For some simple cases model.attributes might be enough
I'll try this approach here and see how it goes, depending on how many edge cases I encounter it might be better to have something different or not
Luca Guidi
@jodosha
Jun 01 2016 13:04
@mrbongiolo Is that because getters != data?
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 13:06
@jodosha coming from rails I've tested associations and stuff, since am:v let me do it, that's why I think that in some cases just transforming a model might not work, but I'm not sure, I'll test it. I guess for most cases model.attributes or something like it would reflect the current state of the model and it would suffice for validations.
Piotr Solnica
@solnic
Jun 01 2016 13:13
@jodosha not yet, it’s been on my todo list
thanks for the heads-up
also, oh node :laughing:
Luca Guidi
@jodosha
Jun 01 2016 13:13
:D
Maciej Mensfeld
@mensfeld
Jun 01 2016 14:48
@solnic it seems that something like that don't work: key(:metadata).maybe { schema(Metadata) }
it fails always without ignoring at all when the key is not present
Piotr Solnica
@solnic
Jun 01 2016 14:49
it's not supported, there's an issue, I'll add support for blocks in 0.8
Maciej Mensfeld
@mensfeld
Jun 01 2016 14:49
@solnic can I bypass it somehow?
Piotr Solnica
@solnic
Jun 01 2016 14:50
key(:metadata) { none? | schema(Metadata) } I think
Maciej Mensfeld
@mensfeld
Jun 01 2016 14:50
nope :(
ArgumentError: +schema+ is not a valid predicate name
Piotr Solnica
@solnic
Jun 01 2016 14:51
right :(
Maciej Mensfeld
@mensfeld
Jun 01 2016 14:51
this is the last thing I need to make everything work :D
it works for arrays: key(:authors).each { empty? | schema(Author) }
but not for nested schemas :( damn
damn
damn
for now I will then stop validating this part :/
Piotr Solnica
@solnic
Jun 01 2016 14:54
I'll be working on this next week
maybe earlier
Maciej Mensfeld
@mensfeld
Jun 01 2016 14:54
I'm still in an early phase with what I build. If you manage to fix this this year that it would be awesome :D
Piotr Solnica
@solnic
Jun 01 2016 14:54
defo this month, don't worry
Maciej Mensfeld
@mensfeld
Jun 01 2016 14:55
:) thanks - dry-validations are awesome
Piotr Solnica
@solnic
Jun 01 2016 15:13
cool, glad it (sort-of) works for you ;)
we've got a bunch of known bugs that are not fixed as I was not doing any oss coding in May
so I'll take care of that in the upcoming weeks and wrap up 0.8.0
Anton Holovko
@kelevro
Jun 01 2016 16:31

Hi, there!
In this class I catch excaption undefined methodkey'`

class Schema < Dry::Validation::Schema::Form
  key(:email) { |email| email.filled? }
end

Could You help me?

Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 16:52
@kelevro which version of dry-validation are you using? the master branch deprecated key in favor or required
Piotr Solnica
@solnic
Jun 01 2016 16:52
that's old-old syntax from 0.6
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 01 2016 16:52
@kelevro also, AFAIK version 0.7.4 uses Schema as block
Anton Holovko
@kelevro
Jun 01 2016 16:53
@mrbongiolo dry-validation (0.7.4)
@mrbongiolo @solnic thanks!
Eduardo de Oliveira Hernandes
@eduardodeoh
Jun 01 2016 22:31
rails/rails#25208 -> Rails = Basecamp
Tim Riley
@timriley
Jun 01 2016 22:51
This is basically an IoC container, right? https://github.com/arkency/command_bus
:tada:
Nikita Shilnikov
@flash-gordon
Jun 01 2016 23:32
:clap: :+1:
Tim Riley
@timriley
Jun 01 2016 23:46
Thanks for your contributions to this, @flash-gordon!