{"id":23430625,"url":"https://github.com/fidme/active_flags","last_synced_at":"2025-04-12T23:07:49.479Z","repository":{"id":56842119,"uuid":"174122611","full_name":"FidMe/active_flags","owner":"FidMe","description":"Rails engine that allows you to flag any model instance. Get rid of all those useless booleans !","archived":false,"fork":false,"pushed_at":"2020-09-28T09:59:18.000Z","size":78,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T23:07:20.053Z","etag":null,"topics":["flags","gem","rails","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FidMe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-06T10:21:44.000Z","updated_at":"2020-09-28T09:59:21.000Z","dependencies_parsed_at":"2022-09-01T06:31:56.230Z","dependency_job_id":null,"html_url":"https://github.com/FidMe/active_flags","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FidMe%2Factive_flags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FidMe%2Factive_flags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FidMe%2Factive_flags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FidMe%2Factive_flags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FidMe","download_url":"https://codeload.github.com/FidMe/active_flags/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643004,"owners_count":21138355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flags","gem","rails","ruby"],"created_at":"2024-12-23T09:39:06.250Z","updated_at":"2025-04-12T23:07:49.449Z","avatar_url":"https://github.com/FidMe.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveFlags\n\n[![Build Status](https://travis-ci.org/FidMe/active_flags.svg?branch=master)](https://travis-ci.org/FidMe/active_flags)\n[![Gem Version](https://badge.fury.io/rb/active_flags.svg)](https://badge.fury.io/rb/active_flags)\n\n\nActive Flags allows you to use automatic flags on models. You won't have to create useless booleans with view logic in your core tables. They should not have been there in the first place, let Active Flags handle them for you!\n\n## Installation\n\n(You need at least rails 5.0 to use the gem)\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'active_flags'\n```\n\nAnd then execute:\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n```bash\n$ gem install active_flags\n```\n\nThen import Active Flags' migrations\n```bash\n$ bin/rails active_flags:install:migrations\n```\n\nAdapt them if needed and run db:migrate\n```bash\n$ rails db:migrate\n```\n\n## Usage\nLet's say you're building a networking app, with users connecting each other.\nBut you want it to be so relevant that it only makes active users (connecting often enough) visibles on the search.\nTo do so you would add a boolean `active` or `visible` in your user's table.\n\nIt works, but it is view logic and shouldn't be there. Imagine your app is growing and you have 10 more booleans on your user table, and then 10 more on another model. It will only pollute your tables.\n\nOnce Active Flags is set, you can easily declare that your model has flags like that:\n\n```ruby\nclass User \u003c ApplicationRecord\n  has_flags :visible, :active\nend\n```\n\nAnd that's it!\nYou can now add flags on a user like that:\n\n```ruby\nuser.flags = { visible: true, active: true }\nuser.save!\n```\n\nA flag won't be saved if you don't explicitly declare it as has_flags attributes in the model.\n\nBut if you do not want to handle explicit flags, you could also declare:\n\n```ruby\nclass User \u003c ApplicationRecord\n  has_flags\nend\n```\n\nAnd then you can declare as much flags as you want with no restriction:\n```ruby\nuser.update!(flags: { visible: true, active: true, diet: 'vegan', power: 'super saiyan' })\n```\n\nTo access your flags, you now have 2 ways.\nEither as a hash, with the `flags` method or as an ActiveFlag::Flag collection with the `flags_as_collection` method.\n\nNote: You can call `converted_value` on an `ActiveFlag::Flag` instance returned by flags_as_collection, to retrieved your 'true' or 'false' value as a boolean.\n\n## Flags as scopes\n\nWhen you develop an app without active_flags, you will generally query the equivalent of flags as simple booleans.\n\nActiveFlags gives you a clean and simple way to query your model based on defined flags.\n\nAny flag can be queried as a scope using the `flagged_as` method\n\n```ruby\nuser = User.create!(flags: { visible: true })\n\nUser.flagged_as_visible\n# #\u003cActiveRecord::Relation [#\u003cUser id: 1\u003e]\u003e \n\nUser.flagged_as_visible(false)\n# #\u003cActiveRecord::Relation []\u003e\n\nUser.flagged_as_intelligent\n# #\u003cActiveRecord::Relation []\u003e\n\nuser.update!(flags: { intelligent: true })\nUser.flagged_as_intelligent\n# #\u003cActiveRecord::Relation [#\u003cUser id: 1\u003e]\u003e \n\nuser.update!(flags: { intelligent: 'a bit' })\nUser.flagged_as_intelligent('a_bit')\n# #\u003cActiveRecord::Relation [#\u003cUser id: 1\u003e]\u003e \n```\n\nTo query flags the other way around you can use the `not_flagged_as` method\n\n```ruby\nUser.not_flagged_as_intelligent\n# or with value\nUser.not_flagged_as_intelligent('a bit')\n```\n\n## Contributing\nhttps://github.com/FidMe/active_flags\n\n## License\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffidme%2Factive_flags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffidme%2Factive_flags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffidme%2Factive_flags/lists"}