Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Piotr Solnica
@solnic
my concern is duplication, not sure how to do it without duplication tbf
I duplicated the word duplication
Andy Holland
@AMHOL
lol
Yeah same with me, but thinking about it more, I don't think it's an issue
Don Morrison
@elskwid
duduplication
Andy Holland
@AMHOL
i.e. schemas and validators should both work stand-alone, just that the validator would assume input of the correct type, but should still make assertions on required keys
i.e. with something like:
module Web
  module Blog
    module Schemas
      module Posts
        Update = Dry::Validation.Form do
          required(:id, :int).value(:int?)

          required(:post).schema do
            required(:title, :str).value(:str?)
            required(:content, :str).value(:str?)
          end
        end
      end
    end
  end
end

module Blog
  module Validators
    module Posts
      Update = Dry::Validation.Schema do
        required(:id)
        required(:title).filled(min_size?: 3)
        required(:content).filled(min_size?: 100)
      end
    end
  end
end
Although in the second case, messages doesn't report on the missing id
require 'dry-validation'

module Blog
  module Validators
    module Posts
      Update = Dry::Validation.Schema do
        required(:id)
      end
    end
  end
end

Blog::Validators::Posts::Update.({})
# => #<Dry::Validation::Result output={} messages={}>
Take it that's a bug?
Tim Riley
@timriley
Or a not-yet-built-for use case, I think
There was some chat about it in here within the last couple of days IIRC
having a dry-v schema with a rule about the key but not the value
Andy Holland
@AMHOL
Yeah, I would think it would assert that the key was present
Although in this case adding .filled is valid
Tim Riley
@timriley
yeah, the problem is that rn I don’t think it does that
That's where the earlier discussion was
My uneasy feeling about the code you've posted is that I feel like I'd probably want my type specs to be inside my domain validation too
otherwise it feels... incomplete
Tim Riley
@timriley
I would just want it to hard-fail if the type specs weren't met, instead of trying to coerce first, which is what you might do on the boundary schemas
Michał Pietrus
@blelump
morning @solnic , I've recently bumped dry-v to the newest version (0.9.5) and there's one thing that used to work in 0.7, but it seems it doesnt in 0.9.5. In particular, you were able to configure configure { config.messages = :i18n } globally
uhm, perhaps I assumed it worked because of this one I18n backend is no longer required and set by default (solnic). Might be related?
Piotr Solnica
@solnic
@blelump yes probably. You can still set it in a single place
Michał Pietrus
@blelump
@solnic , oh, how should I do that ?
Piotr Solnica
@solnic
Define a base schema class and inherit from it
Michał Pietrus
@blelump
I see. Since I'm with Reform, there's some work to do to make it possible
Piotr Solnica
@solnic
Reform should handle it then somehow
Michał Pietrus
@blelump
yup
Tim Riley
@timriley
Interesting Ruby behaviour I encountered today:
Thing = Struct.new(:thing)
# => Thing

Thing.new("hi")
# => #<struct Thing thing="hi">

Array(Thing.new("hi"))
# => ["hi"]
# ಠ_ಠ - my struct object got totally stripped away
I see that this is probably due to Struct#to_a
A(nother) reason it’s probably better to define your own classes for holding small values etc. when you need them.
Piotr Solnica
@solnic
@timriley Struct is a pretty bad API tbf
it’s a) slow!!! b) comes with gotchas like you just mentioned c) splat args in constructor are meh
I initially implemented Message in dry-v using Struct then it turned out to be 2 x slower to instantiate than a custom class with a constructor and attr readers….
Tim Riley
@timriley
wow!
Piotr Solnica
@solnic
I was surprised too, I used to think Struct is a very cheap object
Piotr Solnica
@solnic
@timriley dry-stdlib? O_o
Piotr Solnica
@solnic
@backus do you think we could wrap up dry-struct?
I have a growing need for it in my current project at work…I start having usecases similar to yours, so I’m motivated to help with that
furthermore, we’re gonna have important improvements in dry-types so would be nice to release it, and in master Struct is no more…:)
Nikita Shilnikov
@flash-gordon
@solnic dry-rb/dry-struct#8
Piotr Solnica
@solnic
can somebody remind me why we’re using gemnasium? O_o
Piotr Solnica
@solnic
dry-rb/dry-validation#241 #help-wanted
Igor
@svilenkov
Does anyone can see why am I getting a ArgumentError: wrong number of arguments (1 for 0) for initialize the error points to the line def initialize
class IsobusExportAdapter
  extend Dry::Initializer::Mixin

  attr_reader :gis_api_params

  option :application_map_id
  option :field_id
  option :strategy_bundle_id
  option :worker

  def initialize
  end
end
IsobusExportAdapter.new(application_map_id: 43, field_id: field.id, strategy_bundle_id: bundle.id, worker: user)
Piotr Solnica
@solnic
@keeperhood initialize from Mixin expects arguments
you can’t override it w/o args
Igor
@svilenkov
Can I use *args ?
Piotr Solnica
@solnic
yes