{"id":17681807,"url":"https://github.com/jgaskins/pennant","last_synced_at":"2025-10-19T00:29:51.796Z","repository":{"id":143300936,"uuid":"393870711","full_name":"jgaskins/pennant","owner":"jgaskins","description":"Feature flags in Crystal applications with pluggable backends (in-memory and Redis currently supported)","archived":false,"fork":false,"pushed_at":"2021-08-08T08:08:58.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T06:51:24.532Z","etag":null,"topics":["crystal","feature-flags","feature-toggles"],"latest_commit_sha":null,"homepage":"","language":"Crystal","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/jgaskins.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-08T05:48:36.000Z","updated_at":"2023-07-25T14:48:29.000Z","dependencies_parsed_at":"2023-05-12T03:00:41.355Z","dependency_job_id":null,"html_url":"https://github.com/jgaskins/pennant","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Fpennant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Fpennant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Fpennant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Fpennant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jgaskins","download_url":"https://codeload.github.com/jgaskins/pennant/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246366227,"owners_count":20765652,"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":["crystal","feature-flags","feature-toggles"],"created_at":"2024-10-24T09:12:13.930Z","updated_at":"2025-10-19T00:29:51.685Z","avatar_url":"https://github.com/jgaskins.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pennant\n\nFeature flags for your application, with pluggable backends.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     pennant:\n       github: jgaskins/pennant\n   ```\n\n2. Run `shards install`\n\n## Usage\n\nLoad and configure Pennant:\n\n```crystal\nrequire \"pennant\"\nrequire \"redis\"\n\nredis = Redis::Client.new\n\nPennant.config do |c|\n  c.adapter = Pennant::RedisAdapter.new(redis)\nend\n```\n\nNow, anywhere in your application, you can simply call `Pennant.enabled?(\"my-feature\")` to see if a particular feature flag is enabled.\n\nTo enable or disable a feature flag, you can simply call `Pennant.enable(\"my-feature\")` or `Pennant.disable(\"my-feature\")`, respectively. To run this in production, you can run the following command at a production Bash prompt (assuming your Pennant configuration exists in `./config/pennant.cr`):\n\n```\ncrystal eval 'require \"./config/pennant\"; Pennant.enable \"my-feature\"'\n```\n\nFor example, if your Crystal application is running on Heroku, you can prefix the command with `heroku run ...`. If it's running on Kubernetes, you could prefix it with `kubectl exec -it $POD -- ...`.\n\n### Enabling for a given actor\n\nPennant allows enabling a feature for specific actors, such as specific users, groups. Any object in your application can be used for this purpose as long as it includes the `Pennant::Actor` mixin, which requires defining the `pennant_id` method:\n\n```crystal\nstruct User\n  include Pennant::Actor\n\n  getter id : UUID\n\n  def pennant_id : String\n    \"User:#{id}\"\n  end\nend\n```\n\nThe format of `pennant_id` is up to you, as long as it uniquely identifies that person, group, or concept and resolves to the same value for it every time. For database-backed objects, this is often a class (or table) name and a primary key.\n\nOnce you have this in place, you can check whether a feature is enabled by passing `for: actor` to the `enable`, `disable`, and `enabled?` method:\n\n```crystal\nif Pennant.enabled?(\"my-feature\", for: current_user)\n  # new hotness\nelse\n  # old and busted\nend\n```\n\n### Enabling for a percentage of requests\n\nSometimes you don't necessarily want to enable a feature for the same people, but instead for a percentage of your application's traffic. For this, you can pass `percentage_of_time: 0.1` to `enable`:\n\n```crystal\nPennant.enable(\"my-feature\", percentage_of_time: 0.05)\n```\n\nAll calls to `Pennant.enabled?(\"my-feature\")` will now return `true` 5% of the time. \n\n## Web UI\n\nThere is a web UI in progress to manage feature flags so that you don't need to enable/disable them via production shells. The intent is to be able to insert it into your `HTTP::Server` middleware:\n\n```crystal\nhttp = HTTP::Server.new([\n  HTTP::LogHandler.new,\n  Pennant::Web.new(mount_at: \"/feature_flags\"),\n  # the rest of your HTTP handler entries ...\n])\n```\n\nWith the Lucky framework, you'd insert this into [your `middleware` array](https://luckyframework.org/guides/http-and-routing/http-handlers#built-in-handlers).\n\nWith this in place, if you visit your application at `/feature_flags` you will see a list of your feature flags and their current states.\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/jgaskins/pennant/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Jamie Gaskins](https://github.com/jgaskins) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgaskins%2Fpennant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjgaskins%2Fpennant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgaskins%2Fpennant/lists"}