Coder Social home page Coder Social logo

Comments (7)

solnic avatar solnic commented on August 28, 2024

You have access to rule AST via YourSchema.rules. We need to see how we could use that for hints, it should be enough as all the relevant info is there. I was planning to add a "hint compiler" that would use this AST to produce hints.

from dry-validation.

timriley avatar timriley commented on August 28, 2024

Ah, thanks for pointing me towards .rules! I didn't realise it existed :)

from dry-validation.

solnic avatar solnic commented on August 28, 2024

Right, actually I forgot that it's an AST wrapped in DSL objects, so you gotta do rules.map(&:to_ary) to get a pure AST

from dry-validation.

solnic avatar solnic commented on August 28, 2024

I added support for hints. Is there anything special you need in order to implement your form builder?

from dry-validation.

timriley avatar timriley commented on August 28, 2024

The AST is pretty much all we should need, I think, but the hints will hopefully make it even nicer :)

Feel free to close this on, I reckon, and I can raise smaller things separately if I come across any other issues when we get to integrating the validation.

Thanks :)

On 18 Dec 2015, at 4:40 AM, Piotr Solnica [email protected] wrote:

I added support for hints. Is there anything special you need in order to implement your form builder?


Reply to this email directly or view it on GitHub.

from dry-validation.

solnic avatar solnic commented on August 28, 2024

Roger that

from dry-validation.

kurko avatar kurko commented on August 28, 2024

FYI I needed to get just the keys (incl. nesting) to shove into strong_parameters, so I write this for whoever needs this in the future:

    def self.creative_keys_ast
      [ast_predicate(MySchema)]
    end

    # Recursive algorithm to fetch dry-validation schema's keys
    def self.ast_keys(rule, ast = [])
      if rule.respond_to?(:rules)
        rule.rules.map(&:to_ary).each do |node_rule|
          subtree = ast_keys(node_rule[1].rules[1].rules[1].rules[0])
          if subtree.blank?
            ast << node_rule[0]
          else
            ast << {
              node_rule[0] => subtree
            }
          end
        end
      end

      ast.flatten
    end

I had to figure out how to get those rules arrays used. It looks pretty messy.

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.