Coder Social home page Coder Social logo

Comments (3)

solnic avatar solnic commented on August 28, 2024

I wouldn't want to make the already complex dsl code even more complex with this dual-arity mode. There are already lower level APIs for building up schema rules, these should be used in such cases. They are definitely not polished as the dsl, but I would be more interested in making them robust and simple to use vs messing with the dsl blocks.

from dry-validation.

solnic avatar solnic commented on August 28, 2024

@hooptie45 I was just chatting with Luca from Hanami project about the same thing and prepared a sample script which shows how to build rules manually, I figured I should share here too:

require 'dry-validation'

v = Dry::Validation::Schema::Value.new

v.key(:email).required(:str?)
v.key(:age).required(:int?)

class UserSchema < Dry::Validation::Schema::Form
end

UserSchema.configure do |config|
  config.rules = v.rules
end

schema = UserSchema.new

puts schema.(email: ‘luca@hanami.rb’, age: 'no idea').messages.inspect

from dry-validation.

solnic avatar solnic commented on August 28, 2024

I'm gonna close this one since the DSL won't be changed to support dynamic generation of rules. We have low-level interfaces to do this and even when these are not enough you can always build rule ast yourself. This will be documented properly once we're close to 1.0.0.

from dry-validation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.