{"id":13879569,"url":"https://github.com/bibendi/feature_toggles","last_synced_at":"2025-04-10T04:59:18.510Z","repository":{"id":33229320,"uuid":"154342947","full_name":"bibendi/feature_toggles","owner":"bibendi","description":"This gem provides a mechanism for pending features.","archived":false,"fork":false,"pushed_at":"2022-03-25T13:28:54.000Z","size":46,"stargazers_count":85,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T01:11:09.184Z","etag":null,"topics":["docker","feature-toggles","ruby"],"latest_commit_sha":null,"homepage":"","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/bibendi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-23T14:30:25.000Z","updated_at":"2025-01-29T08:09:48.000Z","dependencies_parsed_at":"2022-08-07T20:16:59.318Z","dependency_job_id":null,"html_url":"https://github.com/bibendi/feature_toggles","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bibendi%2Ffeature_toggles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bibendi%2Ffeature_toggles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bibendi%2Ffeature_toggles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bibendi%2Ffeature_toggles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bibendi","download_url":"https://codeload.github.com/bibendi/feature_toggles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161266,"owners_count":21057554,"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":["docker","feature-toggles","ruby"],"created_at":"2024-08-06T08:02:25.496Z","updated_at":"2025-04-10T04:59:18.478Z","avatar_url":"https://github.com/bibendi.png","language":"Ruby","readme":"[![Gem Version](https://badge.fury.io/rb/feature_toggles.svg)](https://badge.fury.io/rb/feature_toggles)\n[![Build Status](https://travis-ci.org/bibendi/feature_toggles.svg?branch=master)](https://travis-ci.org/bibendi/feature_toggles)\n\n# FeatureToggles\n\nThis gem provides a mechanism for pending features that take longer than a single release cycle. The basic idea is to have a configuration file that defines a bunch of toggles for various features you have pending. The running application then uses these toggles in order to decide whether or not to show the new feature.\n\n\u003ca href=\"https://evilmartians.com/?utm_source=feature_toggles\"\u003e\n\u003cimg src=\"https://evilmartians.com/badges/sponsored-by-evil-martians.svg\" alt=\"Sponsored by Evil Martians\" width=\"236\" height=\"54\"\u003e\u003c/a\u003e\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"feature_toggles\"\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install feature_toggles\n\n## Framework-agnostic usage\n\nFeatures could be defined dynamically\n\n```ruby\nfeatures = FeatureToggles.build do\n  # define env var prefix to enable features\n  # globally by passing MY_PREFIX_BAR=1\n  env \"MY_PREFIX\"\n\n  feature :bar do\n    user.can_bar?\n  end\n\n  feature :foo do |user: nil|\n    !user.nil? \u0026\u0026 user.can_foo?\n  end\nend\n\nfeatures.enabled?(:bar)\nfeatures.enabled?(:bar, user: user)\nfeatures.for(user: user).enabled?(:foo)\n```\n\nor loaded from files\n\n```ruby\nfeatures = FeatureToggles.build([\"/path/to/features.rb\"])\n```\n\n### Rails usage\n\nThis is step-by-step guide to add `feature_toggles` to Rails application.\n\n**Step 0. (optional) Add `features` to User model**\n\n**NOTE**: This is not the part of this gem–you can model you per-user features settings differently.\n\n```ruby\nclass AddFeaturesToUsers \u003c ActiveRecord::Migration\n  def change\n    # we use a `features` array column to store user's active features\n    add_column :users, :features, :string, array: true, default: []\n  end\nend\n```\n\n**Step 1. Define features**\n\nFeatures from file `\u003crails-root-or-engine\u003e/config/features.rb` are loaded by convention.\n\n```ruby\n# config/features.rb\nenv \"FEATURE\"\n\nfeature :chat do |user: nil|\n  user\u0026.features.include?(\"chat\")\nend\n```\n\nFeatures will be available at `Rails.features` after the end of application initialization.\n\n**Step 2. Add `current_features` helper and use it.**\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  # ...\n  helper_method :current_features\n\n  def current_features\n    Rails.features.for(user: current_user)\n  end\nend\n```\n\n**Step 3. Use `current_features`.**\n\nFor example, in your navigation template:\n\n```erb\n\u003cul\u003e\n \u003c% if current_features.enabled?(:chat) %\u003e\n   \u003cli\u003e\u003ca href=\"/chat\"\u003eChat\u003c/a\u003e\u003c/li\u003e\n \u003c% end %\u003e\n\u003c/ul\u003e\n```\n\nOr in your controller:\n\n```ruby\nclass ChatController \u003c ApplicationController\n  def index\n    unless current_features.enabled?(:chat)\n      return render template: \"comming_soon\"\n    end\n  end\nend\n```\n\n### Metadata\n\nYou can add arbitrary metadata to features:\n\n```ruby\nfeature :manual_quantity_backsync, icon: :updated, description: \"Manual quantity sync for imported products\" do |user: nil|\n  !!user\u0026.features\u0026.fetch(\"manual_quantity_backsync\", false)\nend\n```\n\nThat metadata can be later programmatically accessed and exposed into admin panels, API documentation, etc.\n\n```ruby\nRails.features.first.metadata\n# =\u003e { icon: :updated, description: \"Manual quantity sync for imported products\" }\n```\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/bibendi/feature_toggles. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the FeatureToggles project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bibendi/feature_toggles/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbibendi%2Ffeature_toggles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbibendi%2Ffeature_toggles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbibendi%2Ffeature_toggles/lists"}