These are chat archives for dry-rb/chat

31st
May 2016
Ralf Schmitz Bongiolo
@mrbongiolo
May 31 2016 00:50
@aradunovic Usually I set validations as a step of the operation, something like this:
class Create < Resource

  register :schema, Dry::Validation.Schema {
    # validation logic here...
  }

  perform do
    validate :schema
    tee :persist
    map :decorate
  end
end

Some of the operations are more complex, and I separate "params" validation from model and external validations, something like this:

perform do
  validate :schema
  tee_try :validate_resource_status, catch: Errors::UnprocessableEntity
  map :extract_date
  map :compute_period
  try :get_available_members, catch: Errors::UnprocessableEntity
  tee :update
  map :decorate
end

In this case, :validate_resource_status and :get_available_members could raise an UnprocessableEntity error that would be handled back in the controller, I separated those ones from the main schema because the logic on those cases are not directly related to the input. But for most cases I'll have a single :schema that will validate the input, followed by a :persist or something.

Aleksandar Radunović
@aradunovic
May 31 2016 06:54
Wow, nice…thanks guys…
@timriley I asked the question because of create operations on berg. I was wondering why didn’t you separate validation, but now I know.
Tim Riley
@timriley
May 31 2016 07:08
Yeah. I guess everyone can do it in their own way, but this is what’s working for us so far. Seeing those transaction examples just above is something I’ve never done before.
joystick
@joystick
May 31 2016 07:28
Hi there, looking for help with AR scopes. Is there a room for that on gitter please?
Pablo Herrero
@pabloh
May 31 2016 07:29
@joystick, try freenode.net
joystick
@joystick
May 31 2016 07:43
@pabloh Thanks, will try. Which room please?
Pablo Herrero
@pabloh
May 31 2016 07:44
#ruby ;)
joystick
@joystick
May 31 2016 07:50
:+1:
Aleksandar Radunović
@aradunovic
May 31 2016 12:51
is there any way to achieve projects/:id/tasks with multi_route and separate tasks.rb routes
Piotr Solnica
@solnic
May 31 2016 13:11
@mrbongiolo this is pretty nice, thanks for sharing
Oskar Szrajer
@gotar
May 31 2016 13:13
yeap it's possible I think. If you set Roda route for project as:
r.on "projects"
    r.on :id 
        r.on "taska" do
             r.route "tasks"   
        end
    end
end
and on taska you will have specific one for taska with r.is it should works, I assume
Aleksandar Radunović
@aradunovic
May 31 2016 13:30
@gotar Thanks man, it works!
Ralf Schmitz Bongiolo
@mrbongiolo
May 31 2016 15:15
Piotr Solnica
@solnic
May 31 2016 15:15
yep
I18n is very slow, but we cache it, so it should be a huge difference
it as in message templates, so the lookup is triggered only once
Ralf Schmitz Bongiolo
@mrbongiolo
May 31 2016 15:16
Uhm
so 2nd requests should be faster?
Nice, really all subsequent request are way faster
Piotr Solnica
@solnic
May 31 2016 15:24
yeah, I’ll make it faster but it’s gonna be a continues effort spanning multiple versions
I hoped to make it for 0.8.0 but it’s too much work for me in one month
so I’ll start for 0.9.0
I need to rewrite error/hint compilers, basically
Ralf Schmitz Bongiolo
@mrbongiolo
May 31 2016 15:32
Wouldn't it be faster to store error messages in a JSON file also?
Any reason why rails and a lot of libs prefer yaml for configs?
Luca Guidi
@jodosha
May 31 2016 15:35
@mrbongiolo I think it was picked as tool in the early Rails days, and then cargo culted
Ralf Schmitz Bongiolo
@mrbongiolo
May 31 2016 15:37
@jodosha yeah, you're probably right
unless there's some hidden reason somewhere :D
Piotr Solnica
@solnic
May 31 2016 15:40
well editing yaml is nicer than editing json
Ralf Schmitz Bongiolo
@mrbongiolo
May 31 2016 15:41
Yeah, a bit, but JSON is better for putting "anywhere" and is reasonably human readable...
Nikita Shilnikov
@flash-gordon
May 31 2016 15:49
@mrbongiolo you can place json in yo yaml so you can edit json while u edit yaml
yo dawg
Jeff Dickey
@jdickey
May 31 2016 15:50
Question about Dry::Types::Value, Types::Class, and constraints: is it possible to define a Class attribute in a value object and require that it respond to certain messages?
Ralf Schmitz Bongiolo
@mrbongiolo
May 31 2016 15:54
@flash-gordon JSON inception style!! hahaha
Ralf Schmitz Bongiolo
@mrbongiolo
May 31 2016 16:07
@timriley What are your thoughts on having a "splatted" version of dry-transaction steps? I'm on a rails env and on most of my operations I end up needing a model or something, right now, for some operations I'm just sending my output like this: [model, input.merge(something)], and then on the next step: -> args { model, input = args }, it works but it's kind of not so dry to get the values every time from the args.
Another solution I came up is calling my operations like this: MyOperation.with(@model, @something_else).call(params) { ... }, then all the arguments in with will be added on a variable step_options that is send to all steps. So I can have my steps registered like that: register :a_step, -> model, something_else, input { ... }.
Another things that I might do is to have an option in the step, like call_with_user_options that would indicate if that step should use the step_options or not.
It seems a bit hacky, but I find it better then "injecting" those dependencies directly into the input hash.
Chase Gilliam
@Ch4s3
May 31 2016 19:48
would a dry-encryption gem for encrypting database columns make sense to anyone else?
Ralf Schmitz Bongiolo
@mrbongiolo
May 31 2016 19:56
Not sure, wouldn't just an ORM need it or something?
Ralf Schmitz Bongiolo
@mrbongiolo
May 31 2016 20:01
and I guess that the current crypto libs are good enough for general purpose, but I'm not sure
Chase Gilliam
@Ch4s3
May 31 2016 20:19
My thought was that a lot of existing solutions like https://github.com/jmazzi/crypt_keeper are pretty tightly coupled to ActiveRecord
it would be nice if there was a gem that made it easy to encrypt/decrypt fields without relying on AR
Chase Gilliam
@Ch4s3
May 31 2016 20:25
Not sure if it makes sense though
Tim Riley
@timriley
May 31 2016 22:51
Look for our newest badge:
Screen Shot 2016-06-01 at 8.51.10 AM.png
Chase Gilliam
@Ch4s3
May 31 2016 23:52
🙌🏻