Title: | Turn Features On and Off using Feature Flags |
---|---|
Description: | Feature flags allow developers to turn features of their software on and off in form of configuration. This package provides functions for creating feature flags in code. It exposes an interface for defining own feature flags which are enabled based on custom criteria. |
Authors: | Ryszard Szymański [aut, cre] |
Maintainer: | Ryszard Szymański <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2024-11-17 03:24:23 UTC |
Source: | https://github.com/szymanskir/featureflag |
Creates an instance of a bool feature flag with the specified bool value.
create_bool_feature_flag(value)
create_bool_feature_flag(value)
value |
single logical determining whether the flag should be enabled |
feature flag object of the bool value
{ enabled_flag <- create_bool_feature_flag(TRUE) disabled_flag <- create_bool_feature_flag(FALSE) }
{ enabled_flag <- create_bool_feature_flag(TRUE) disabled_flag <- create_bool_feature_flag(FALSE) }
It should not be used directly, but only as a prerequisite when creating concrete feature flag.
create_feature_flag()
create_feature_flag()
instance of a base feature flag.
Creates an instance of a percentage feature flag with a specified chance of being enabled
create_percentage_feature_flag(percentage)
create_percentage_feature_flag(percentage)
percentage |
chance of being enabled e.g. 1 for always being enabled |
feature flag object of the percentage type
{ always_enabled_flag <- create_percentage_feature_flag(percentage = 1) randomly_enabled_flag <- create_percentage_feature_flag(percentage = 0.5) }
{ always_enabled_flag <- create_percentage_feature_flag(percentage = 1) randomly_enabled_flag <- create_percentage_feature_flag(percentage = 0.5) }
Creates an instance of a time period feature flag.
create_time_period_feature_flag(from = NULL, to = NULL)
create_time_period_feature_flag(from = NULL, to = NULL)
from |
date-time from which the feature flag should be enabled set as null if you want a one sided boundary. |
to |
date-time to which the feature flag should be enabled set as null if you want a one sided boundary |
Boundaries are set as inclusive
{ two_sided_flag <- create_time_period_feature_flag( from = ISOdatetime(2020, 10, 10, 0, 0, 0, tz = "UTC"), to = ISOdatetime(2020, 11, 10, 0, 0, 0, tz = "UTC") ) left_sided_flag <- create_time_period_feature_flag( from = ISOdatetime(2020, 10, 10, 0, 0, 0, tz = "UTC") ) right_sided_flag <- create_time_period_feature_flag( to = ISOdatetime(2020, 10, 10, 0, 0, 0, tz = "UTC") ) }
{ two_sided_flag <- create_time_period_feature_flag( from = ISOdatetime(2020, 10, 10, 0, 0, 0, tz = "UTC"), to = ISOdatetime(2020, 11, 10, 0, 0, 0, tz = "UTC") ) left_sided_flag <- create_time_period_feature_flag( from = ISOdatetime(2020, 10, 10, 0, 0, 0, tz = "UTC") ) right_sided_flag <- create_time_period_feature_flag( to = ISOdatetime(2020, 10, 10, 0, 0, 0, tz = "UTC") ) }
Evaluates the provided expression if the feature flag is enabled.
feature_if(feature_flag, expr)
feature_if(feature_flag, expr)
feature_flag |
flag which defines whether the provided expression should be evaluated |
expr |
expression to evaluate when the feature_flag is enabled |
The passed expression is evaluated in the frame where feature_if
is called.
If the passed feature_flag
is enabled, than the result of the evaluation
of the passed expression is returned. Otherwise there is no return value.
{ flag <- create_bool_feature_flag(TRUE) feature_if(flag, { 2 + 7 }) }
{ flag <- create_bool_feature_flag(TRUE) feature_if(flag, { 2 + 7 }) }
Evaluates one or the other expression based on whether the feature flag is enabled.
feature_ifelse(feature_flag, true_expr, false_expr)
feature_ifelse(feature_flag, true_expr, false_expr)
feature_flag |
flag which defines which expression should be evaluated |
true_expr |
expression to evaluate when the feature_flag is enabled |
false_expr |
expression to evaluate when the feature_flag is disabled |
The passed expression is evaluated in the frame where feature_ifelse
is called.
The result of evaluating true_expr
is returned if the passed feature_flag
is enabled. Otherwise the result of evaluating false_expr
is returned.
{ flag <- create_bool_feature_flag(TRUE) feature_ifelse( flag, 2 * 7, 3 * 7 ) }
{ flag <- create_bool_feature_flag(TRUE) feature_ifelse( flag, 2 * 7, 3 * 7 ) }
Checks if the given feature flag is enabled.
is_enabled(feature_flag)
is_enabled(feature_flag)
feature_flag |
feature flag to be tested whether it is enabled |
TRUE if the feature flag is enabled.
Checks if the given bool feature flag is enabled
## S3 method for class 'bool_feature_flag' is_enabled(feature_flag)
## S3 method for class 'bool_feature_flag' is_enabled(feature_flag)
feature_flag |
flag to be checked whether it is enabled |
TRUE if the feature flag is enabled.
{ enabled_flag <- create_bool_feature_flag(TRUE) if (is_enabled(enabled_flag)) { print("The flag is enabled!") } }
{ enabled_flag <- create_bool_feature_flag(TRUE) if (is_enabled(enabled_flag)) { print("The flag is enabled!") } }
Checks if the given percentage flag is enabled
## S3 method for class 'percentage_feature_flag' is_enabled(feature_flag)
## S3 method for class 'percentage_feature_flag' is_enabled(feature_flag)
feature_flag |
flag to be checked whether it is enabled |
TRUE if the feature flag is enabled.
{ enabled_flag <- create_percentage_feature_flag(1) if (is_enabled(enabled_flag)) { print("The flag is enabled!") } }
{ enabled_flag <- create_percentage_feature_flag(1) if (is_enabled(enabled_flag)) { print("The flag is enabled!") } }
Checks if the given bool feature flag is enabled
## S3 method for class 'time_period_feature_flag' is_enabled(feature_flag)
## S3 method for class 'time_period_feature_flag' is_enabled(feature_flag)
feature_flag |
flag to be checked whether it is enabled |
TRUE if the feature flag is enabled.
{ feature_flag <- create_time_period_feature_flag( from = ISOdatetime(2020, 10, 10, 0, 0, 0, tz = "UTC") ) if (is_enabled(feature_flag)) { print("The flag is enabled!") } }
{ feature_flag <- create_time_period_feature_flag( from = ISOdatetime(2020, 10, 10, 0, 0, 0, tz = "UTC") ) if (is_enabled(feature_flag)) { print("The flag is enabled!") } }