{"id":19027638,"url":"https://github.com/danielefongo/features","last_synced_at":"2025-04-23T14:47:51.622Z","repository":{"id":57501297,"uuid":"421432651","full_name":"danielefongo/features","owner":"danielefongo","description":"Enable or disable code using feature toggles","archived":false,"fork":false,"pushed_at":"2021-11-11T06:58:39.000Z","size":55,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T12:22:55.654Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielefongo.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":"2021-10-26T13:18:36.000Z","updated_at":"2021-11-11T07:00:31.000Z","dependencies_parsed_at":"2022-09-14T19:41:19.817Z","dependency_job_id":null,"html_url":"https://github.com/danielefongo/features","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielefongo%2Ffeatures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielefongo%2Ffeatures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielefongo%2Ffeatures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielefongo%2Ffeatures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielefongo","download_url":"https://codeload.github.com/danielefongo/features/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250456833,"owners_count":21433722,"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":[],"created_at":"2024-11-08T21:08:46.689Z","updated_at":"2025-04-23T14:47:51.599Z","avatar_url":"https://github.com/danielefongo.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Features\n\nFeatures is an Elixir porting of [rust cargo features](https://doc.rust-lang.org/cargo/reference/features.html).\n\n## Disclaimer\n\n**This package is experimental!**\n\nUnexpected behavior may happen, so please try this library and [open an issue](https://github.com/danielefongo/features/issues/new) if you find a bug 💜.\n\n## Installation\n\nAdd `features` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:features, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Usage\n\nOn `config.exs`:\n\n```elixir\nconfig :features, features: [:a_feature]\n```\n\nOn code:\n\n```elixir\ndefmodule MyModule do\n  use Features\n\n  @doc \"A doc for do_something/0 function.\"\n  # this will enable the next function with his doc if :a_feature is in config\n  @feature :a_feature\n  def do_something do\n    :a_feature_is_enabled\n\n    # this will enable the next statement if :another_feature is in config\n    @feature :another_feature\n    :another_feature_is_enabled\n\n    # this will enable the next statement if :another_feature is not in config\n    @feature_off :another_feature\n    :another_feature_is_disabled\n  end\nend\n```\n\nCode is automatically removed during compilation if the feature condition is not met.\n\nA config example is the following:\n\n```elixir\nconfig :features, features: [:a_feature]\n```\n### Testing\n\nTo test featured code you have to set features property to enable runtime execution (it replaces the compile-time deletion).\n\nOn `test.exs`:\n```elixir\nconfig :features, test: true\n```\n\nOn `test_helpers.exs`:\n\n```elixir\nFeatures.Test.start()\n```\n\nOn a test:\n\n```elixir\ndefmodule MyModuleTest do\n  use ExUnit.Case, async: true\n  use Features.Test\n\n  featured_test \"test1\", features: [:a_feature, :another_feature] do\n    assert MyModule.do_something() == :another_feature_is_enabled\n  end\n\n  featured_test \"test2\", features: [:a_feature] do\n    assert MyModule.do_something() == :another_feature_is_disabled\n  end\n\n  featured_test \"test3\", features: [] do\n    assert_raise CaseClauseError, fn -\u003e MyModule.do_something() end\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielefongo%2Ffeatures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielefongo%2Ffeatures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielefongo%2Ffeatures/lists"}