janlelis / has_many_booleans Goto Github PK
View Code? Open in Web Editor NEWThis Rails plugin/gem allows you to generate virtual boolean attributes, which get saved in the database as a single bitset integer.
License: MIT License
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
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 :)
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).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.