{"id":13507910,"url":"https://github.com/securingsincity/molasses","last_synced_at":"2025-04-14T04:32:18.386Z","repository":{"id":62429905,"uuid":"75495857","full_name":"securingsincity/molasses","owner":"securingsincity","description":"Feature toggle library for elixir","archived":false,"fork":false,"pushed_at":"2017-05-01T23:36:16.000Z","size":61,"stargazers_count":78,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T18:55:19.125Z","etag":null,"topics":["ecto","elixir","feature-flags","feature-toggles","redis"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/securingsincity.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":"2016-12-03T19:36:52.000Z","updated_at":"2025-03-12T19:58:14.000Z","dependencies_parsed_at":"2022-11-01T20:06:43.401Z","dependency_job_id":null,"html_url":"https://github.com/securingsincity/molasses","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/securingsincity%2Fmolasses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/securingsincity%2Fmolasses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/securingsincity%2Fmolasses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/securingsincity%2Fmolasses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/securingsincity","download_url":"https://codeload.github.com/securingsincity/molasses/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248821929,"owners_count":21166981,"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":["ecto","elixir","feature-flags","feature-toggles","redis"],"created_at":"2024-08-01T02:00:42.656Z","updated_at":"2025-04-14T04:32:14.400Z","avatar_url":"https://github.com/securingsincity.png","language":"Elixir","funding_links":[],"categories":["Feature Flags and Toggles"],"sub_categories":[],"readme":"# Molasses\n\n[![Build Status](https://travis-ci.org/securingsincity/molasses.svg?branch=master)](https://travis-ci.org/securingsincity/molasses)\n[![Coverage Status](https://coveralls.io/repos/github/securingsincity/molasses/badge.svg?branch=master)](https://coveralls.io/github/securingsincity/molasses?branch=master)\n\nA feature toggle library using redis or SQL (using Ecto) as a backing service. It allows you to roll out to users based on a percentage. Alternatively, you can use Molasses to deploy to a group of users or user ids.\n\n## Installation\n\n  1. Add `molasses` to your list of dependencies in `mix.exs` and run `mix deps.get`:\n\n  ```elixir\n  def deps do\n    [{:molasses, \"~\u003e 0.2.0\"}]\n  end\n  ```\n  2. Install related dependencies by including `ExRedis`, `MongoDB` or `Ecto` and one of its adapter libraries for Postgres or Mysql.\n\n  2A. Redis\n\n  For Redis, you will just need to include `exredis`:\n\n  ```elixir\n  def deps do\n    [\n      {:molasses, \"~\u003e 0.2.0\"},\n      {:exredis, \"\u003e= 0.2.4\"}\n    ]\n  end\n  ```\n\n  2B. SQL using Ecto\n\n  For Ecto with PostgreSQL, install `ecto` and `postgrex`. You will also need to start ecto and postgrex as applications:\n\n  ```elixir\n  def deps do\n    [\n      {:molasses, \"~\u003e 0.2.0\"},\n      {:ecto, \"~\u003e 2.1.1\"},\n      {:postgrex, \"\u003e= 0.0.0\"}\n    ]\n  end\n\n  def application do\n    [applications: [:ecto, :postgrex]]\n  end\n  ```\n\n  Your config will also need to change. You will need to set up an Ecto Repo like you would [here](https://hexdocs.pm/ecto/Ecto.html#module-repositories). As well as set the Molasses adapter to postgres.\n\n  ```elixir\n  # molasses adapter setting\n  config :molasses, adapter: \"ecto\"\n  ```\n\n  You will need to create an ecto migration and add the features tables.\n\n  ```elixir\n\n    defmodule Repo.CreateTestMocks do\n      use Ecto.Migration\n\n      def change do\n        create table(:features) do\n          add :name, :string\n          add :percentage, :integer\n          add :users, :string\n          add :active, :boolean\n        end\n\n        create index(:features, [:name])\n      end\n    end\n  ```\n\n  2C. MongoDB\n\n  ```elixir\n  def deps do\n    [\n      {:molasses, \"~\u003e 0.2.0\"},\n      {:mongodb, \"\u003e= 0.0.0\"},\n    ]\n  end\n  ```\n\n  For a working example of how to set up Molasses look at [Molasses Example](https://github.com/securingsincity/molasses-example)\n\n## Usage\n\nMolasses uses the same interface whether you are using Redis or SQL. Each function takes an `Ecto.Repo` or the `ExRedis` client as the first argument.\n\n### Activate\n\n* `activate/2` - Activates a feature for all users.\n* `activate/3` -  Activates a feature for some users.\n  *  When the last argument is an integer then it sets the feature active for a percentage of users.\n  *  When the last argument is a string then it sets a feature active for that specific user or user group.\n  *  When the last argument is a list then it sets a feature active for that specific list of users or user groups\n\n### Deactivate\n\n* `deactivate/2` - Dectivates a feature for all users.\n\n### Checking to see if a feature is active\n\n* `is_active/2` - Check to see if a feature is active for all users.\n* `is_active/3` - Check to see if a feature is active for a specific user.\n\n\n## Examples\n\n### Redis\n```elixir\n\n# Create a new redis client\n{:ok, client} = Exredis.start_link\n\n# activate a feature\nMolasses.activate(client, \"my_feature\")\n\n# activate a feature for a percentage of users\nMolasses.activate(client, \"my_feature\", 75)\n\n# activate a feature for a subset of integer based userIds\nMolasses.activate(client, \"my_feature\", [2, 4, 5])\n\n# activate a feature for a subset of string based userIds (think a mongoId) or a list of groups\nMolasses.activate(client, \"my_feature\", [\"admins\", \"super admins\"])\n\n# activate a feature for only one group of users\nMolasses.activate(client, \"my_feature\", \"powerusers\")\n\n# checking if a feature is active for all users\nMolasses.is_active(client, \"my_feature\")\n\n# checking if a feature is active for a specific user (based on percentage, or user id/group)\nMolasses.is_active(client, \"my_feature\", identifier)\n\n# deactivate a feature\nMolasses.deactivate(client, \"my_feature\")\n```\n\n### Ecto\n\n```elixir\n# Switched to ecto as my adapter\nApplication.put_env(:molasses,:adapter, \"ecto\")\n\n# alias the Repo for use\nalias Molasses.Test.Repo\n\n# use is_active and activate the same way but it uses the Ecto repo instead of\nMolasses.activate(Repo, \"my_feature\", 75)\nMolasses.is_active(Repo, \"my_feature\")\n```\n\n\n### MongoDB\n\n```elixir\n# Switched to ecto as my adapter\nApplication.put_env(:molasses,:adapter, \"mongo\")\n\n\n# Create a new mongo client\n{:ok, conn} = Mongo.start_link(database: \"molasses\")\n\n\n# use is_active and activate the same way but it uses the Ecto repo instead of\nMolasses.activate(conn, \"my_feature\", 75)\nMolasses.is_active(conn, \"my_feature\")\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecuringsincity%2Fmolasses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecuringsincity%2Fmolasses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecuringsincity%2Fmolasses/lists"}