Manager API reference¶
This document describes the Switch Manager API. This is generally referred to
as the global gargoyle
object, which lives in gargoyle.gargoyle
.
-
class
gargoyle.manager.
SwitchManager
(*args, **kwargs)¶ -
get_all_conditions
()¶ Returns a generator which yields groups of lists of conditions.
>>> for set_id, label, field in gargoyle.get_all_conditions(): >>> print("%(label)s: %(field)s" % (label, field.label))
-
get_condition_set_by_id
(switch_id)¶ Given the identifier of a condition set (described in ConditionSet.get_id()), returns the registered instance.
-
get_condition_sets
()¶ Returns a generator yielding all currently registered ConditionSet instances.
-
is_active
(key, *instances, **kwargs)¶ Returns
True
if any ofinstances
match an active switch. Otherwise returnsFalse
.>>> gargoyle.is_active('my_feature', request)
-
register
(condition_set)¶ Registers a condition set with the manager.
>>> condition_set = MyConditionSet() >>> gargoyle.register(condition_set)
-
unregister
(condition_set)¶ Unregisters a condition set with the manager.
>>> gargoyle.unregister(condition_set)
-
Switches are handled through the ModelDict
interface, which is registered under the Switch
model.
-
class
gargoyle.models.
Switch
(*args, **kwargs)¶ Stores information on all switches. Generally handled through an instance of
ModelDict
, which is registered under the globalgargoyle
namespace.value
is stored with by type label, and then by column:>>> { >>> namespace: { >>> id: [[INCLUDE, 0, 50], [INCLUDE, 'string']] // 50% of users >>> } >>> }
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
add_condition
(manager, condition_set, field_name, condition, exclude=False, commit=True)¶ Adds a new condition and registers it in the global
gargoyle
switch manager.If
commit
isFalse
, the data will not be written to the database.>>> switch = gargoyle['my_switch'] >>> condition_set_id = condition_set.get_id() >>> switch.add_condition(condition_set_id, 'percent', '0-50', exclude=False)
-
clear_conditions
(manager, condition_set, field_name=None, commit=True)¶ Clears conditions given a set of parameters.
If
commit
isFalse
, the data will not be written to the database.Clear all conditions given a ConditionSet, and a field name:
>>> switch = gargoyle['my_switch'] >>> condition_set_id = condition_set.get_id() >>> switch.clear_conditions(condition_set_id, 'percent')
You can also clear all conditions given a ConditionSet:
>>> switch = gargoyle['my_switch'] >>> condition_set_id = condition_set.get_id() >>> switch.clear_conditions(condition_set_id)
-
get_active_conditions
(manager)¶ Returns a generator which yields groups of lists of conditions.
>>> for label, set_id, field, value, exclude in gargoyle.get_all_conditions(): >>> print("%(label)s: %(field)s = %(value)s (exclude: %(exclude)s)" % (label, field.label, value, exclude))
-
remove_condition
(manager, condition_set, field_name, condition, commit=True)¶ Removes a condition and updates the global
gargoyle
switch manager.If
commit
isFalse
, the data will not be written to the database.>>> switch = gargoyle['my_switch'] >>> condition_set_id = condition_set.get_id() >>> switch.remove_condition(condition_set_id, 'percent', [0, 50])
-
exception