Giter Site home page Giter Site logo

janlelis / has_many_booleans Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 2.0 635 KB

This Rails plugin/gem allows you to generate virtual boolean attributes, which get saved in the database as a single bitset integer.

License: MIT License

Ruby 100.00%

has_many_booleans's People

Contributors

janlelis avatar jellehelsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

has_many_booleans's Issues

Validations for booleans

I had another though for an addition in your library.
I'm sorry that i haven't had found time to fork your repo to make an example but here goes anyhow.

There should be way to validate if any of the possible options where checked.
Not sure how the syntax would be, perhaps something like validates_accepted_any :fieldname ?

And the implementation would be pretty much like @booleans_data.reject { |k, v| k.blank? || !v[1] }.any? So it would filter out any keys that are nil, or which boolean value is in FALSE_VALUES.

Dunno if this makes sense, just something i needed in one project :)

Instantiating new objects with arguments

Seems that doing Model.new(:boolean_argument_active => true) does not work, as the boolean fields are not yet created, so the model will not respond to respective attributes, so assigning will fail.

Also defining the boolean accessors before calling super in initialize won't work as the method defining logic depends on AR::Base stuff already being wired and responding to db attributes.

One solution would be to call super without any arguments, then initialize the boolean column methods, and then assign self.attributes = *args (initialize calls the same setter internally anyhow, so everything should be solid)

Another issue is that the extension will not treat form values the same way ActiveRecord does. Meaning "0" and "false" are treated as true, whereas for consistency they should be treated as normally. This can be achieved via comparing the new value (given to the setter) with ActiveRecord::ConnectionAdapters::ColumnDefinition::TRUE_VALUES or FALSE_VALUES to easily parse the boolean value. I guess this could be done via mapping the FALSE_VALUES to has_many_booleans :false_values options, but this still would mean that "foobar" would pass as true (unless its additionally mapped).

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.