{"id":26448523,"url":"https://github.com/indrode/feature_setting","last_synced_at":"2025-03-18T14:34:53.914Z","repository":{"id":34301100,"uuid":"38209398","full_name":"indrode/feature_setting","owner":"indrode","description":"A lightweight feature/setting DSL for Rails applications.","archived":false,"fork":false,"pushed_at":"2021-09-14T02:31:25.000Z","size":105,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-17T07:36:21.983Z","etag":null,"topics":["rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"FutureMind/recycler-fast-scroll","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/indrode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-28T18:27:18.000Z","updated_at":"2021-09-14T02:48:12.000Z","dependencies_parsed_at":"2022-07-15T17:17:12.216Z","dependency_job_id":null,"html_url":"https://github.com/indrode/feature_setting","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indrode%2Ffeature_setting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indrode%2Ffeature_setting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indrode%2Ffeature_setting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indrode%2Ffeature_setting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/indrode","download_url":"https://codeload.github.com/indrode/feature_setting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244240930,"owners_count":20421553,"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":["rails","ruby"],"created_at":"2025-03-18T14:34:52.253Z","updated_at":"2025-03-18T14:34:53.908Z","avatar_url":"https://github.com/indrode.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# feature_setting\n\n[![Gem\nVersion](https://badge.fury.io/rb/feature_setting.svg)](https://badge.fury.io/rb/feature_setting)\n[![Code\nClimate](https://codeclimate.com/github/indrode/feature_setting/badges/gpa.svg)](https://codeclimate.com/github/indrode/feature_setting)\n[![Test\nCoverage](https://codeclimate.com/github/indrode/feature_setting/badges/coverage.svg)](https://codeclimate.com/github/indrode/feature_setting/coverage)\n[![security](https://hakiri.io/github/indrode/feature_setting/master.svg)](https://hakiri.io/github/indrode/feature_setting/master)\n\nThis gem introduces the concept of \"features\" and \"settings\" to your Rails app. It provides an easy way to define such features and settings with default values right in your code and will persist them in the database.\n\n- a feature is a key that can either be enabled or disabled\n- a setting is a key that has a value (of type String, Fixnum, Float, Array, or Hash)\n\nIn practice, features can be used to switch certain functionality in your code on or off. This can be used to roll out functionality without the need to deploy. Settings are very flexible in that they can hold any value. The possibilities are endless. They should not be used to store application secrets, such as tokens, passwords, and keys. Those type of settings should rather be stored in environment variables using tools like [https://github.com/bkeepers/dotenv](dotenv).\n\nBoth, features and settings are configured in your code with default values. They can then be updated at any time in the Rails console and persist in the database.\n\n```ruby\n# using features:\nif Feature.caching_enabled?\n  # do this\nelse\n  # do that\nend\n\n# using settings:\nif Setting.error_threshold \u003e 500\n    # do this\nend\n\nif Setting.allowed_users.include?(current_user.id)\n  # do that\nend\n```\n\n## Installation\n\nAdd the gem to your application's Gemfile:\n\n```ruby\ngem 'feature_setting'\n```\n\nNow run the `feature_setting` installation:\n\n    $ rails generate feature_setting:install\n\nThis generates a migration file. To run this migration:\n\n    $ rake db:migrate\n\nThe next step is to define your Feature and/or Setting classes.\n\n## Usage\n\n### Features\n\nTo create a new Feature class, inherit a class from `FeatureSetting::Feature` (if using a gem version prior to `1.2.0` use `FeatureSetting::FsFeature`). Then define your features in a hash called `FEATURES` and call `init_features!`.\n\n```ruby\nclass Features \u003c FeatureSetting::Feature\n  FEATURES = {\n    newfeature: true\n  }\n\n  init_features!\nend\n```\n**Note:** You can call `init_features!(true)` to remove any existing features that are not defined anymore\n\nFor each key you have defined, a class method `keyname_enabled?` is generated. You can now do the following:\n\n```ruby\nFeatures.newfeature_enabled? # =\u003e true\nFeatures.disable!(:newfeature)\nFeatures.newfeature_enabled? # =\u003e false\nFeatures.enable!(:newfeature)\nFeatures.newfeature_enabled? # =\u003e true\n```\n\nOr you can use these shortcuts:\n\n```ruby\nFeatures.enable_newfeature!\nFeatures.disable_newfeature!\n```\n\nDefault values for features are defined in your class and current values are persisted in the database.\n\n### Settings\n\nTo create a new Setting class, inherit a class from `FeatureSetting::Setting` (if using a gem version prior to `1.2.0` use `FeatureSetting::FsSetting`). Then define your settings in a hash called `SETTINGS` and call `init_settings!`. The following example shows the setup and some possible definitions.\n\n```ruby\nclass Settings \u003c FeatureSetting::Setting\n  SETTINGS = {\n    setting_one:   12300,\n    setting_two:   'some string',\n    setting_three: %w(one two three),\n    setting_four:  ENV['SETTING_FOUR'],\n    setting_five:  { key1: 'value1', key2: 'value2' },\n    setting_six:   true\n  }\n\n  init_settings!\nend\n```\n\n**Note:** You can call `init_settings!(true)` to remove any existing settings that are not defined anymore\n\nYou can now do the following:\n\n```ruby\nSettings.setting_one # =\u003e 12300\nSettings.setting_one = 2000\nSettings.setting_one # =\u003e 2000\n```\n\n**NEW IN VERSION 1.6:** Hashes values can be updated individually and will not overwrite the entire hash:\n```ruby\nSettings.setting_five = { key1: 'another_value' }\n=\u003e setting_five:  { key1: 'another_value', key2: 'value2' }\n\nSettings.setting_five = { key3: 'value3' }\n=\u003e setting_five:  { key1: 'another_value', key2: 'value2', key3: 'value3' }\n```\n\nDefault values for settings are defined in your class and current values are persisted in the database.\n\nSettings support the following datatypes:\n\n```\nBoolean\nString\nInteger\nFloat\nSymbol\nArray\nHash\n```\n\n### Advanced Features\n\nSettings and features can be reset to their default values as configured in your class definition:\n\n```ruby\nFeatures.reset_features!\nSettings.reset_settings!\n```\n\nDisplay all defined keys:\n\n```ruby\nFeatures.defined_features\nSettings.defined_settings\n```\n\nCache settings or features:\n\n```ruby\nFeatures.cache_features!\nSettings.cache_settings!\n```\nNote that a simple call to `Features.init_features!` or `Settings.init_settings!` respectively will remove caching.\n\nYou can create as many Setting or Feature classes as you desire. Here are some examples:\n\n```ruby\nSearchSettings.levenshtein_distance\nTestFeatures.experimental_search_enabled?\n```\n\n## Contributing\n\n1. Fork it (https://github.com/indrode/feature_setting/fork)\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\nNotes:\n\n- Contributions without tests won't be accepted.\n- Please don't update the gem version.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015, 2016, 2017, 2018, 2019 Indro De ([http://indrode.com](http://indrode.com))\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findrode%2Ffeature_setting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findrode%2Ffeature_setting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findrode%2Ffeature_setting/lists"}