Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 10:30
    solnic commented #32
  • Dec 05 09:29

    solnic on master

    Clear exception message when an… Add gem names to plugins Merge pull request #128 from sk… (compare)

  • Dec 05 09:29
    solnic closed #128
  • Dec 05 09:29
    solnic closed #127
  • Dec 04 18:49
    micahphone starred dry-rb/dry-monads
  • Dec 04 17:43
    icy-arctic-fox starred dry-rb/dry-types
  • Dec 02 12:37
    pedrofurtado starred dry-rb/dry-view
  • Dec 02 11:59
    lenon starred dry-rb/dry-monads
  • Dec 01 11:06

    flash-gordon on declare-finalized

    (compare)

  • Dec 01 11:06

    flash-gordon on master

    Set initial value for ivar Merge pull request #131 from dr… (compare)

  • Dec 01 11:06
    flash-gordon closed #131
  • Dec 01 11:05
    flash-gordon opened #131
  • Dec 01 11:03

    flash-gordon on declare-finalized

    Set initial value for ivar (compare)

  • Nov 30 16:50
    paul commented #32
  • Nov 30 16:50
    paul synchronize #32
  • Nov 30 16:44
    paul synchronize #32
  • Nov 30 16:02
    paul synchronize #32
  • Nov 30 16:01
    paul commented #32
  • Nov 30 12:12

    flash-gordon on master

    Use GH badge for CI status (compare)

Tim Riley
@timriley
where that MyCommaSeparatedList type would accept string input and coerce it into an array
Alexey Zapparov
@ixti
@timriley mm, yeah. that will definitely work for me indeed. Thanks!
Alexey Zapparov
@ixti
Was it considered change API a bit? like instead of Dry::Validation.Form it would be better to write Dry::Validation::Form.describe imho :D
I'm OK with current API. It just looks a bit awkward to me :D
As awkward as when I see someone uses :: to call method
Christian
@bakku
In dry-validation is there a difference between required(:name) and required(:name).filled?
Andy Holland
@AMHOL
required(:name) means the hash key is required, .filled? means the value must be non-blank
Ralf Schmitz Bongiolo
@mrbongiolo
Is there a way to coerce array values with dry-validation?
Tim Riley
@timriley
@mrbongiolo what sort of thing would you like to achieve?
Ralf Schmitz Bongiolo
@mrbongiolo
@timriley Actually I have a form that sends IDs, but as string, I would like to coerce them to Integer, something like:
optional(:my_ids, [:nil, :array]).each([:nil, :int], :int?)
Tim Riley
@timriley
OK cool. And is this a Dry::Validation.Form schema?
Fran Worley
@fran-worley
@mrbongiolo I use Types::Form::Array.member(Types::Form::Int) works perfectly in my Reform form to do exactly as you describe
Ralf Schmitz Bongiolo
@mrbongiolo
Thanks @fran-worley I'll try this out :)
It worked like a charm!!! Thanks for the help, I had forgotten about the member key on Dry::Types
Tim Riley
@timriley
Can we see your final result, @mrbongiolo? :)
Thanks @fran-worley :)
Ralf Schmitz Bongiolo
@mrbongiolo
Sure @timriley, here it is:
# first I defined my custom Dry Type
module MyApp
  module Types
    include Dry::Types.module
    ArrayOfInts = Types::Form::Array.member(Types::Form::Int)
  end
end

# Then I use it on my Schema
optional(:my_ids, [:nil, MyApp::Types::ArrayOfInts]).each(:int?)
Tim Riley
@timriley
right, very nice :)
Ralf Schmitz Bongiolo
@mrbongiolo
Is there an easy way to say that the schema should be valid only if one specific key is given and none of the others, or only some of the others? Or I would need to list all the other keys on a custom rule?
Tim Riley
@timriley
just on the schema still, another way could be like this:
optional(:my_ids, [:nil, :array]).each([:nil, Types::Form::Int], :int?)
or something like that, using dry-types’ coercing form types
if you wanted to avoid creating an “ArrayOfInts” type just for this purpose
That’s why I was asking whether it was .Form schema, I was wondering if/how that worked with the new type specs
Ralf Schmitz Bongiolo
@mrbongiolo
@timriley so each accept a type as first argument?
I'm using Dry::Validation.Form with type_spec = true on the configs
I've tried your suggestions, but then I get this error: +nil+ is not a valid predicate name
Tim Riley
@timriley
ah, I probably got it wrong, sorry
Tim Riley
@timriley
It’s an interesting question though, the intersection of type specs and each
Ralf Schmitz Bongiolo
@mrbongiolo
Yes, I guess it makes sense to be able to coerce array values in the way that you expressed. Not sure if that would be doable or way to off of what each() proposes
Christian Meier
@mkristian
hi, I am looking for some way to share validation rules between server and javascript client. I wonder if dry-validation can export its 'rules' in one way or the other ?
Andy Holland
@AMHOL
@mkristian I've thought about this a lot in the past, the best solution I could think of was a custom verb like DESCRIBE to build the model representation on start-up, but I think just sticking to server-side validation is the better option
Having said that dry-validation builds an AST, so you could use that to create some representation of the validation predicates
Christian Meier
@mkristian
that sound interesting.
server side validation is easier but with javascript only clients not an option - anymore
Andy Holland
@AMHOL
Not sure what you mean, surely you send your data to the server at some point?
Christian Meier
@mkristian
yes, we do but client side validation is much more responsive. the AST idea I will look into it. as we already decided to have only 'simple' validation on the client and all those custom and more complex stuff stays on the server
Andy Holland
@AMHOL
Yeah, it would be nice in an ideal world, I just think the cost outweighs the benefits personally
Christian Meier
@mkristian
I personally are more on your side but it is not my decision I just need to find a solution :)
Fran Worley
@fran-worley
If you really don't want to write the js validations yourself you could just Ajax the data on change to the server and display any errors
Christian Meier
@mkristian
@fran-worley I want to have both and want to share the validation rules at some of them between the client and the server
Andy Holland
@AMHOL
Well if a client/my boss asked me to do that, my suggested solution would be let's leave that rabbit hole alone, have the user hit submit and display the errors in one hit, but I know that's not always an option :p
Christian Meier
@mkristian
well, I was hopping (not too much) that there is already some solution out there with dry-validation
but from hear I get the courage and question the client side validation approach tomorrow - let's see what response I get
Andy Holland
@AMHOL
Cool, well if you end up having to implement it and need help, feel free to post on https://discuss.dry-rb.org/, it will require some intimate knowledge of the library and would be an interesting project, so would be nice to have it documented
Christian Meier
@mkristian
sure will do
Andy Holland
@AMHOL
FYI you can return the ast like this:
require 'bundler/inline'
gemfile(true) { gem 'dry-validation' }

s = Dry::Validation.Schema(build: false) do
  required(:age) { int? & gt?(18) }
end

s.ast
# => [[:rule, [:age, [:and, [[:rule, [:age, [:predicate, [:key?, [[:name, :age], [:input, Undefined]]]]]], [:rule, [:age, [:and, [[:rule, [:age, [:key, [:age, [:predicate, [:int?, [[:input, Undefined]]]]]]]], [:rule, [:age, [:key, [:age, [:predicate, [:gt?, [[:num, 18], [:input, Undefined]]]]]]]]]]]]]]]]]
Christian Meier
@mkristian
cool
George Millo
@georgemillo
how do people test their dry-v schemas, if at all?
I started writing some custom RSpec matchers, then I realised that my spec files were practically identical to my schemas themselves:
# schema:
required(:name).filled
optional(:age).maybe

# spec:
expect(schema).to have_required_key(:name).filled
expect(schema).to have_optional_key(:age).maybe