From 976f747e4dc892da9f61fdb312f0d49e2e37b243 Mon Sep 17 00:00:00 2001 From: Mark Markaryan Date: Wed, 3 Jan 2024 17:08:04 -0800 Subject: [PATCH 1/2] removing the concept of possible_deployment_environments (turned out to be more confusing than useful, in practice) --- README.md | 3 +-- config/config.exs | 1 - lib/simple_feature_flags.ex | 15 ++++++--------- mix.exs | 2 +- test/simple_feature_flags_test.exs | 2 -- 5 files changed, 8 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 453977a..2acd1b6 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,6 @@ Here is an example of the output: ... config :simple_feature_flags, :flags, %{ current_deployment_environment: :test, - possible_deployment_environments: [:test, :localhost, :staging, :production], features: %{ new_algorithm: %{enabled_in: [:localhost, :staging]}, new_ui: %{enabled_in: [:localhost]} @@ -98,4 +97,4 @@ def deps do end ``` -The docs can be found at . \ No newline at end of file +The docs can be found at . diff --git a/config/config.exs b/config/config.exs index 62e101b..d07afb3 100644 --- a/config/config.exs +++ b/config/config.exs @@ -2,7 +2,6 @@ import Config config :simple_feature_flags, :flags, %{ current_deployment_environment: :test, - possible_deployment_environments: [:test, :localhost, :staging, :production], features: %{ test_feature_1: %{enabled_in: [:all]}, test_feature_2: %{enabled_in: :all}, diff --git a/lib/simple_feature_flags.ex b/lib/simple_feature_flags.ex index 9513a12..73d01c6 100644 --- a/lib/simple_feature_flags.ex +++ b/lib/simple_feature_flags.ex @@ -13,7 +13,7 @@ defmodule SimpleFeatureFlags do """ def enabled?(feature) do - possible_deployment_environments = + enabled_in_these_environments = Application.get_env(:simple_feature_flags, :flags).features |> Map.fetch!(feature) |> Map.fetch!(:enabled_in) @@ -21,10 +21,10 @@ defmodule SimpleFeatureFlags do current_deployment_environment = Application.get_env(:simple_feature_flags, :flags).current_deployment_environment - :all == possible_deployment_environments or - [:all] == possible_deployment_environments or - :all in possible_deployment_environments or - current_deployment_environment in possible_deployment_environments + :all == enabled_in_these_environments or + [:all] == enabled_in_these_environments or + :all in enabled_in_these_environments or + current_deployment_environment in enabled_in_these_environments end @doc """ @@ -33,7 +33,7 @@ defmodule SimpleFeatureFlags do ## Examples iex> SimpleFeatureFlags.current_configuration_to_string() - "Current Deployment Environment: :test\\nPossible Deployment Environments: [:test, :localhost, :staging, :production]\\nFeatures:\\n - test_feature_1, enabled in [:all]\\n - test_feature_2, enabled in :all\\n - test_feature_3, enabled in [:test]\\n - test_feature_4, enabled in [:staging, :test, :production]\\n - test_feature_5, enabled in [:staging, :production]\\n - test_feature_6, enabled in []\\n" + "Current Deployment Environment: :test\\nFeatures:\\n - test_feature_1, enabled in [:all]\\n - test_feature_2, enabled in :all\\n - test_feature_3, enabled in [:test]\\n - test_feature_4, enabled in [:staging, :test, :production]\\n - test_feature_5, enabled in [:staging, :production]\\n - test_feature_6, enabled in []\\n" """ def current_configuration_to_string() do @@ -44,16 +44,13 @@ defmodule SimpleFeatureFlags do @doc false def configuration_to_string(%{ current_deployment_environment: current_deployment_environment, - possible_deployment_environments: possible_deployment_environments, features: features }) when is_atom(current_deployment_environment) and current_deployment_environment != nil and - is_list(possible_deployment_environments) and is_map(features) do """ Current Deployment Environment: #{inspect(current_deployment_environment)} - Possible Deployment Environments: #{inspect(possible_deployment_environments)} Features: """ <> (for {feature_name, %{enabled_in: enabled_in}} <- features do diff --git a/mix.exs b/mix.exs index 31c9659..b621f71 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule SimpleFeatureFlags.MixProject do [ app: :simple_feature_flags, description: "Simple feature flags", - version: "0.1.1", + version: "0.1.2", elixir: "~> 1.14", start_permanent: Mix.env() == :prod, deps: deps(), diff --git a/test/simple_feature_flags_test.exs b/test/simple_feature_flags_test.exs index f54612b..50b3120 100644 --- a/test/simple_feature_flags_test.exs +++ b/test/simple_feature_flags_test.exs @@ -33,7 +33,6 @@ defmodule SimpleFeatureFlagsTest do assert SimpleFeatureFlags.current_configuration_to_string() == """ Current Deployment Environment: :test - Possible Deployment Environments: [:test, :localhost, :staging, :production] Features: - test_feature_1, enabled in [:all] - test_feature_2, enabled in :all @@ -50,7 +49,6 @@ defmodule SimpleFeatureFlagsTest do assert SimpleFeatureFlags.configuration_to_string(configuration) == """ Current Deployment Environment: :test - Possible Deployment Environments: [:test, :localhost, :staging, :production] Features: - test_feature_1, enabled in [:all] - test_feature_2, enabled in :all From da73d68c9442ae73a30b56a907a5f64528ba2fd9 Mon Sep 17 00:00:00 2001 From: Mark Markaryan Date: Wed, 3 Jan 2024 17:11:13 -0800 Subject: [PATCH 2/2] updating README to remove mentions of Possible deployment environment --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 2acd1b6..c1e49bb 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,6 @@ Here is an example of the output: ```text Current Deployment Environment: :test - Possible Deployment Environments: [:test, :localhost, :staging, :production] Features: - new_algorithm, enabled in [:localhost, :staging] - new_ui, enabled in [:localhost] @@ -92,7 +91,7 @@ The package can be installed by adding `simple_feature_flags` to your list of de ```elixir def deps do [ - {:simple_feature_flags, "~> 0.1.0"} + {:simple_feature_flags, "~> 0.1"} ] end ```