-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ♻️ Rename settings -> feature flags This is a start at encapsulating the format of the Config map. * ♻️ Introduce Config.Preferences module Refactor existing use of preferences to use new module. * ♻️ Encapsulate EvaluationFormula and rules * ♻️ Move entry matching to config modules
- Loading branch information
1 parent
fc129c9
commit ead514d
Showing
31 changed files
with
417 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
defmodule ConfigCat.Config.EvaluationFormula do | ||
@moduledoc false | ||
alias ConfigCat.Config | ||
alias ConfigCat.Config.PercentageRule | ||
alias ConfigCat.Config.RolloutRule | ||
|
||
@type opt :: {:value, Config.value()} | ||
@type t :: %{String.t() => term()} | ||
|
||
@percentage_rules "p" | ||
@rollout_rules "r" | ||
@value "v" | ||
@variation_id "i" | ||
|
||
@spec new([opt]) :: t() | ||
def new(opts \\ []) do | ||
%{ | ||
@value => opts[:value] | ||
} | ||
end | ||
|
||
@spec percentage_rules(t()) :: [PercentageRule.t()] | ||
def percentage_rules(formula) do | ||
Map.get(formula, @percentage_rules, []) | ||
end | ||
|
||
@spec rollout_rules(t()) :: [RolloutRule.t()] | ||
def rollout_rules(formula) do | ||
Map.get(formula, @rollout_rules, []) | ||
end | ||
|
||
@spec value(t()) :: Config.value() | ||
@spec value(t(), Config.value() | nil) :: Config.value() | nil | ||
def value(formula, default \\ nil) do | ||
Map.get(formula, @value, default) | ||
end | ||
|
||
@spec variation_id(t()) :: Config.variation_id() | nil | ||
@spec variation_id(t(), Config.variation_id() | nil) :: Config.variation_id() | nil | ||
def variation_id(formula, default \\ nil) do | ||
Map.get(formula, @variation_id, default) | ||
end | ||
|
||
@spec variation_value(t(), Config.variation_id()) :: Config.value() | nil | ||
def variation_value(formula, variation_id) do | ||
if variation_id(formula) == variation_id do | ||
value(formula) | ||
else | ||
rollout_value = rollout_rule_variation_value(formula, variation_id) | ||
|
||
if is_nil(rollout_value) do | ||
percentage_rule_variation_value(formula, variation_id) | ||
else | ||
rollout_value | ||
end | ||
end | ||
end | ||
|
||
defp rollout_rule_variation_value(formula, variation_id) do | ||
formula | ||
|> rollout_rules() | ||
|> Enum.find_value(nil, &RolloutRule.variation_value(&1, variation_id)) | ||
end | ||
|
||
defp percentage_rule_variation_value(formula, variation_id) do | ||
formula | ||
|> percentage_rules() | ||
|> Enum.find_value(nil, &PercentageRule.variation_value(&1, variation_id)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule ConfigCat.Config.PercentageRule do | ||
@moduledoc false | ||
alias ConfigCat.Config | ||
|
||
@type t :: %{String.t() => term()} | ||
|
||
@percentage "p" | ||
@value "v" | ||
@variation_id "i" | ||
|
||
@spec percentage(t()) :: non_neg_integer() | ||
def percentage(rule) do | ||
Map.get(rule, @percentage, 0) | ||
end | ||
|
||
@spec value(t()) :: Config.value() | ||
def value(rule) do | ||
Map.get(rule, @value) | ||
end | ||
|
||
@spec variation_id(t()) :: Config.variation_id() | nil | ||
def variation_id(rule) do | ||
Map.get(rule, @variation_id) | ||
end | ||
|
||
@spec variation_value(t(), Config.variation_id()) :: Config.value() | nil | ||
def variation_value(rule, variation_id) do | ||
if variation_id(rule) == variation_id do | ||
value(rule) | ||
end | ||
end | ||
end |
Oops, something went wrong.