{"id":29955002,"url":"https://github.com/foca/flagpole","last_synced_at":"2025-08-03T17:09:10.222Z","repository":{"id":56846646,"uuid":"37828886","full_name":"foca/flagpole","owner":"foca","description":"Store multiple flags in an Integer field by using a bitmap","archived":false,"fork":false,"pushed_at":"2015-06-22T00:59:23.000Z","size":118,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-29T02:17:40.814Z","etag":null,"topics":["bitfield","flags","lesscode","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/foca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-21T22:36:36.000Z","updated_at":"2023-04-04T22:12:38.000Z","dependencies_parsed_at":"2022-09-09T01:01:14.797Z","dependency_job_id":null,"html_url":"https://github.com/foca/flagpole","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/foca/flagpole","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fflagpole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fflagpole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fflagpole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fflagpole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foca","download_url":"https://codeload.github.com/foca/flagpole/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fflagpole/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267392582,"owners_count":24079927,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bitfield","flags","lesscode","ruby"],"created_at":"2025-08-03T17:09:09.552Z","updated_at":"2025-08-03T17:09:10.214Z","avatar_url":"https://github.com/foca.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flagpole: Simple bitmap for storing flags\n\n![](https://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Expo_2010_Shanghai_flags_and_China_Pavilion.jpg/1024px-Expo_2010_Shanghai_flags_and_China_Pavilion.jpg)\n\nFlagpole allows bundling a bunch of flags into a single integer field, by\nstoring each flag as a bit.\n\n``` ruby\nnotifications_via = Flagpole.new([:email, :sms, :phone_push])\nnotifications_via.to_h #=\u003e { email: false, sms: false, phone_push: false }\n\nnotifications_via[:email] = true\nnotifications_via[:sms] = true\n\nnotifications_via.to_h #=\u003e { email: true, sms: true, phone_push: false }\nnotifications_via.to_i #=\u003e 3\n```\n\nNow you can just store that `3` in your database. In order to get that back,\njust pass it to the constructor:\n\n``` ruby\nnotifications_via = Flagpole.new(3, [:email, :sms, :phone_push])\nnotifications_via.to_h #=\u003e { email: true, sms: true, phone_push: false }\n```\n\n## Install\n\n    gem install flagpole\n\n## What kind of sorcery is this?!\n\nIf you consider each flag as a \"bit\" (1 when true, 0 when false), then the above\nexample could be represented as `[1, 1, 0]`. If you reverse this, you get the\nbinary representation of the number `3` (`11`).\n\nAll Flagpole does is give you a nice API to treat sets of named binary settings\n(\"flags\") as an integer, by doing the marshaling for you.\n\n[Read more about bitmaps on Wikipedia](https://en.wikipedia.org/wiki/Bit_field).\n\n## I want to add a new flag\n\nEasy! Just add a new name **at the end** of the array of flag names. So, In the\nexample above, if you later add support for twitter notifications, just do this:\n\n``` ruby\nnotifications_via = Flagpole.new(3, [:email, :sms, :phone_push, :twitter])\nnotifications_via.to_h #=\u003e { email: true, sms: true, phone_push: false, twitter: false }\n```\n\nAs you see, the values are maintained.\n\nIf you wanted the new flag to default to `true`, you just need to increment all\nthe values. You do this by using `#value_of`:\n\n``` ruby\nflags = Flagpole([:email, :sms, :phone_push, :twitter])\nflags.value_of(:twitter) #=\u003e 8\n```\n\nNow all you have to do is add `8` to all your stored values, and voila, everyone\nhas twitter notifications enabled.\n\n## I want to remove an existing flag\n\nIn order to remove a flag, you will need to modify the integer values from your\nstorage. Assuming the example from above, let's say you no longer wish to\nsupport SMS notifications.\n\nIn order to find out the value to substract, you can use `#value_of`:\n\n``` ruby\nflags = Flagpole([:email, :sms, :phone_push, :twitter])\nflags.value_of(:sms) #=\u003e 2\n```\n\nNow you need to substract 2 from all the values that _have the SMS flag set_. In\norder to do this, you need to do a _bitwise and_ between the value and `2`.\nThose that are non-zero, are the ones that have it set. In SQL this would be:\n\n``` sql\nUPDATE users\nSET notification_settings = notification_settings - 2\nWHERE notification_settings \u0026 2 \u003c\u003e 0\n```\n\n## License\n\nThis project is shared under the MIT license. See the attached [LICENSE][] file\nfor details.\n\nPhoto credit: [_Cesarexpo via Wikimedia Commons_](https://commons.wikimedia.org/wiki/File%3AExpo_2010_Shanghai_flags_and_China_Pavilion.jpg).\n\n[LICENSE]: ./LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoca%2Fflagpole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoca%2Fflagpole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoca%2Fflagpole/lists"}