Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Tim Riley
@timriley
Yeah, I guess Matcher.new makes the matcher object, and then you run it with a a "match block" against some kind of value
/me will think about those names a little more
Steve
@dnd
is there a way to get the errors from dry-validation as symbols/keys instead of text sentences? I'm looking to get output like {amount: [:missing, :min_size]} or something like that
Nick Sutterer
@apotonick
@timriley "match block", i just called it handler, but yeah
Martín Fernández
@bilby91
Hello, do I need to require something in order to use Types::Maybe ?
Tim Riley
@timriley
Yeah, it's an "extension" now, @bilby91 - I'm on my phone right now but if you grep the specs for :maybe, you should see how it's done.
Martín Fernández
@bilby91
Perfect! Will check
Thanks @timriley

Is this correct ?

# frozen_string_literal: true
class User < Dry::Struct
  attribute :id, Types::Strict::Int
  attribute :source_url, Types::Strict::String
  attribute :width, Types::Maybe::Float
  attribute :height, Types::Maybe::Float
  attribute :format, Types::Maybe::String
end

I’m getting NameError: Float cannot be autoloaded from an anonymous class or module

Nick Sutterer
@apotonick
@bilby91 did you require the types file?
Tim Riley
@timriley
I've never seen this error. Are you using this inside Rails?
Yeah, you might want to explicitly require the file where you set up the Types module
Nick Sutterer
@apotonick
@timriley how can i know whether or not a matcher has executed a "handler"?
Martín Fernández
@bilby91
My bad, I was missing Strict or Coercible on the Maybe types
I’m working on a rails project
Tim Riley
@timriley
@apotonick how do you mean?
Nick Sutterer
@apotonick
@timriley matcher.(result) #=> no handler was found ? how do i know
add my own handler?
Tim Riley
@timriley
Ahh. Hmm, there no authoritative way to know right now.
Nick Sutterer
@apotonick
@timriley could we add a special return value at some point? not too important right now
Tim Riley
@timriley
Yeah, we could look at something like that.
Nick Sutterer
@apotonick
just designing the Endpoint API for Trailblazer
Tim Riley
@timriley
Another way to do it is to make sure you have enough cases defined to cover all potential inputs
Nick Sutterer
@apotonick
yeah but i'm making it customizable
Tim Riley
@timriley
The marcher won't let you pass a match block that is inexhaustive
Martín Fernández
@bilby91
When using Maybe it is required to add the optional keys on the initializer hash ?
Nick Sutterer
@apotonick
we have a default matcher provided by TRB, and then the user can have another
Tim Riley
@timriley
I.e. It'll require you have at least one of each case
Steve
@dnd
@timriley is there any way to do my question above regarding dry-validation errors?
Nick Sutterer
@apotonick
@dnd we will sort this out in reform soon, the dry-v/errors API
Tim Riley
@timriley
@dnd there should be a way, the error strings are compiled from raw data after all - can you post your question on discuss.dry-rb.org?
@apotonick mind filing a GH issue about indicating when a matched block has been run and no case has matched?
Nick Sutterer
@apotonick
@timriley thanks, will do when the Endpoint draft is running
Tim Riley
@timriley
👍🏼
Nikita Shilnikov
@flash-gordon
@bilby91 Maybe types should behave as Default, so whether keys are mandatory or not depends on what constructor_type you use
Martín Fernández
@bilby91
@flash-gordon Is there any doc on how the constructors work ?
Nick Sutterer
@apotonick
my favorite question haha
Martín Fernández
@bilby91
jja
Nick Sutterer
@apotonick
i get it asked around 10x a week
Martín Fernández
@bilby91
:( sorry to be one of them!
Nikita Shilnikov
@flash-gordon
@bilby91 here dry-rb/dry-rb.org#104 :P
Martín Fernández
@bilby91
Crystal clear now :)
Nick Sutterer
@apotonick
crystal?
Martín Fernández
@bilby91
@apotonick like super clear what type of constructor_types are ? :)
Nick Sutterer
@apotonick
@bilby91 got it :P
Alfonso Perez
@alfonsoperez
Hi there!
I got introduced to these gems by a coworker and they are actually making me love my daily work with Ruby!
I have been trying to implement new functionality with Structs and Types, but I am getting a uninitialized constant Types::MyType (NameError), any ideas?
Tim Riley
@timriley
Can you show us how you defined MyType, @alfonsoperez?