Skip to content

Commit

Permalink
removing the concept of possible_deployment_environments (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
markmark206 authored Jan 4, 2024
1 parent 240dbac commit f48f400
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -67,7 +66,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]}
Expand All @@ -93,9 +91,9 @@ 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
```

The docs can be found at <https://hexdocs.pm/simple_feature_flags>.
The docs can be found at <https://hexdocs.pm/simple_feature_flags>.
1 change: 0 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
15 changes: 6 additions & 9 deletions lib/simple_feature_flags.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ 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)

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 """
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 0 additions & 2 deletions test/simple_feature_flags_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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
Expand Down

0 comments on commit f48f400

Please sign in to comment.