Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
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?
Alfonso Perez
@alfonsoperez
Sure!, thanks!, I created a new file under /engines/mymodel/lib (this is a rails project), /engines/mymodel/lib/types.rb
module MyModel::Types
  include Types.module # this is in /app/types/app.rb 
  ...
  AnswerOutcome = Types::Strict::String.enum('expired', 'verified', 'unverifiable', 'flag')
end
and in /app/types/arr.rb ...
Dry::Types.register_class(Question)

module Types
  include Dry::Types.module
end
one hint I guess is that it says Types::AnswerOutcome, where it should say MyModel::Types::AnswerOutcome
Alfonso Perez
@alfonsoperez
(I am doing MyModel::Types::AnswerOutcome in another file and that's where it's failing)
Luca Guidi
@jodosha
@wafcio @solnic yay! :sparkles: :clap:
Steve
@dnd
I'm trying to validate an object that has an array of hashes where I want the sum of values from one of the hash keys to match a key from the main object. {total: 123, items: [{amount: 22}, {amount: 193}]} What complicates this is that I was thinking of defining the validation on items, but that means that if there are validation issues with some of the other content in the items hashes that the errors returned may sometimes be an array of error strings, other times an array of error hashes