Store up to 64 boolean flags in a single integer column with ActiveRecord using bit arrays.
ActiveFlag is a Ruby gem that allows developers to store multiple boolean flags as a bit array within a single integer column in ActiveRecord. It solves the problem of managing numerous boolean attributes—like user preferences or settings—without cluttering the database with many columns, offering efficient storage and querying.
Ruby on Rails developers who need to manage multiple boolean values in their models efficiently, particularly those working with user profiles, preferences, or feature flags.
Developers choose ActiveFlag for its clean API, performance benefits from bitwise operations, and simplicity—enabling easy flag management without migrations for new flags, all in a minimal, hackable codebase.
Bit array for ActiveRecord
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Groups multiple boolean values into a single integer column, eliminating the need for migrations when adding new flags, as highlighted in the README's key features.
Uses bitwise operations for database queries, which the README states are faster than traditional OR-based boolean checks, improving performance for flag-based filtering.
Provides simple instance methods like set and unset, plus scope methods such as where_languages, making flag management clean and developer-friendly as demonstrated in the usage examples.
Integrates with Rails i18n for human-readable flag names in multiple languages, enabling easy translation for internationalized applications, as shown in the README's translation section.
Works with Rails FormBuilder and SimpleForm via the pairs collection method, simplifying UI implementation for multi-select checkboxes without extra boilerplate.
Supports only up to 64 flags per column due to integer storage constraints, making it unsuitable for models with extensive boolean sets, as implied by the recommendation to use Bitwise for huge arrays.
Relies on bitwise operations that may behave inconsistently across different database systems, potentially complicating deployments in heterogeneous environments.
Lacks built-in support for advanced validations or hooks specific to flag changes, requiring additional custom code for complex business logic around flag states.