-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fallback function so users can customize default values. (#79)
* Add fallback function so users can customize default values. * Clean up new unit test. * Defer evaluation of fallback for catch-all exception. * Update documenation for fallback function feature. * Add unit test for context usage in fallback function. * Fix mock requirement. * Add pytest-mock.
- Loading branch information
1 parent
438479c
commit af0bcd6
Showing
9 changed files
with
92 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,17 +55,29 @@ custom_strategies | Custom strategies you'd like UnleashClient to support. | N | | |
### Checking if a feature is enabled | ||
|
||
A check of a simple toggle: | ||
``` | ||
```Python | ||
client.is_enabled("My Toggle") | ||
``` | ||
|
||
Specifying a default value: | ||
``` | ||
```Python | ||
client.is_enabled("My Toggle", default_value=True) | ||
``` | ||
|
||
Supplying application context: | ||
``` | ||
```Python | ||
app_context = {"userId": "[email protected]"} | ||
client.is_enabled("User ID Toggle", app_context) | ||
``` | ||
|
||
Supplying a fallback function: | ||
```Python | ||
def custom_fallback(feature_name: str, context: dict) -> bool: | ||
return True | ||
|
||
client.is_enabled("My Toggle", fallback_function=custom_fallback) | ||
``` | ||
|
||
- Must accept the fature name and context as an argument. | ||
- Client will evaluate the fallback function once per call of `is_enabled()`. Please keep this in mind when creating your fallback function! | ||
- If both a `default_value` and `fallback_function` are supplied, client will define the default value by `OR`ing the default value and the output of the fallback function. |
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 |
---|---|---|
|
@@ -26,21 +26,33 @@ client.destroy() | |
## Checking if a feature is enabled | ||
|
||
A check of a simple toggle: | ||
``` | ||
```Python | ||
client.is_enabled("My Toggle") | ||
``` | ||
|
||
Specifying a default value: | ||
``` | ||
```Python | ||
client.is_enabled("My Toggle", default_value=True) | ||
``` | ||
|
||
Supplying application context: | ||
``` | ||
```Python | ||
app_context = {"userId": "[email protected]"} | ||
client.is_enabled("User ID Toggle", app_context) | ||
``` | ||
|
||
Supplying a fallback function: | ||
```Python | ||
def custom_fallback(feature_name: str, context: dict) -> bool: | ||
return True | ||
|
||
client.is_enabled("My Toggle", fallback_function=custom_fallback) | ||
``` | ||
|
||
- Must accept the fature name and context as an argument. | ||
- Client will evaluate the fallback function once per call of `is_enabled()`. Please keep this in mind when creating your fallback function! | ||
- If both a `default_value` and `fallback_function` are supplied, client will define the default value by `OR`ing the default value and the output of the fallback function. | ||
|
||
## Logging | ||
|
||
Unleash Client uses the built-in logging facility to show information about errors, background jobs (feature-flag updates and metrics), et cetera. | ||
|
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