Coder Social home page Coder Social logo

How to use Volt::Boolean? about volt HOT 2 OPEN

myknbani avatar myknbani commented on June 25, 2024
How to use Volt::Boolean?

from volt.

Comments (2)

afaur avatar afaur commented on June 25, 2024

Hello @myknbani

Thanks for opening this issue, I do not know the answer to your question and it is not extremely clear to me either. I saw the only example I could find of it here (https://github.com/voltrb/docs/blob/7a496e81ed547407fb57ef62eedf0c655afa27f5/en/docs/models.md#fields) which does not show it being populated via seeding.

If someone could chime in here on this it would be much appreciated. Here are some points of interest in the code regarding Volt::Boolean..

https://github.com/voltrb/volt/blob/eae99c12c0b6cda5730303edefd3bc4da5d406f4/lib/volt/models/validators/type_validator.rb

https://github.com/voltrb/volt/blob/eae99c12c0b6cda5730303edefd3bc4da5d406f4/lib/volt/utils/boolean_patch.rb

# Fails on opal because no True/False class

@myknbani Would you mind putting up on github an example project that reproduces this issue so that it can be easily investigated further? I am sure that would help other people interested in determining what they need to do to implement the desired behavior.

from volt.

myknbani avatar myknbani commented on June 25, 2024

@afaur Thanks for chiming in.

I think it's because of

if value.is_a?(type_rest)

true.is_a?(Volt::Boolean) is false.

A quick tinkering with the Volt console shows this issue:

[2] volt(main)> class Foo < Volt::Model
[2] volt(main)*   field :cute, Volt::Boolean
[2] volt(main)* end  
=> :cute=

[3] volt(main)> f = store._foos.buffer(cute: true)
=> #<Foo id: "5885..657b", cute: true>

[4] volt(main)> f.validate!
=> #<Promise(47396377599140): #<Volt::Errors {:cute=>["must be true or false"]}>>

[5] volt(main)> class Bar < Volt::Model
[5] volt(main)*   field :evil, [TrueClass, FalseClass]
[5] volt(main)* end  
=> :evil=

[6] volt(main)> b = store._bars.buffer(evil: false)
=> #<Bar id: "f6d5..5c94", evil: false>

[7] volt(main)> b.validate!
=> #<Promise(47396380736960): #<Volt::Errors {}>>

from volt.

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.