Contents:
copyright: |
|
---|---|
license: | Apache License 2.0, see LICENSE for more details. |
A Condition is the configuration of an argument, its attribute and an operator. It tells you if it itself is true or false given an input.
The argument defines what this condition is checking. Perhaps it’s a User or Request object. The attribute name is then extracted out of an instance of the argument to produce a variable. That variable is then compared to the operator to determine if the condition applies to the input or not.
For example, for the request IP address, you would define a Request argument, that had an ip property. A condition would then be constrcted like so:
from myapp.gutter import RequestArgument from gutter.client.models import Condition
>> condition = Condition(argument=RequestArgument, attribute=’ip’, operator=some_operator)
When the Condition is called, it is passed the input. The argument is then called (constructed) with input object to produce an instance. The attribute is then extracted from that instance to produce the variable. The extacted variable is then checked against the operator.
To put it another way, say you wanted a condition to only allow your switch to people between 15 and 30 years old. To make the condition:
- You would create a UserArgument class that takes a user object in its constructor. The class also has an age method which returns the user object’s age.
- You would then create a new Condition via: Condition(argument=UserInput, attriibute='age', operator=Between(15, 30)).
- You then call that condition with a User, and it would return True if the age of the user the UserArgument instance wraps is between 15 and 30.
Returns if the condition applies to the inpt.
If the class inpt is an instance of is not the same class as the condition’s own argument, then False is returned. This also applies to the NONE input.
Otherwise, argument is called, with inpt as the instance and the value is compared to the operator and the Value is returned. If the condition is negative, then then not the value is returned.
Keyword Arguments: inpt – An instance of the Input class.
The Manager holds all state for Gutter. It knows what Switches have been registered, and also what Input objects are currently being applied. It also offers an active method to ask it if a given switch name is active, given its conditions and current inputs.
Special singleton used to represent a “no input” which arguments can look for and ignore
Register a switch and persist it to the storage.
A switch encapsulates the concept of an item that is either ‘on’ or ‘off’ depending on the input. The swich determines this by checking each of its conditions and seeing if it applies to a certain input. All the switch does is ask each of its Conditions if it applies to the provided input. Normally any condition can be true for the Switch to be enabled for a particular input, but of switch.componded is set to True, then all of the switches conditions need to be true in order to be enabled.
See the Condition class for more information on what a Condition is and how it checks to see if it’s satisfied by an input.
A dicitonary of changes to the switch since last saved.
Switch changes are a dict in the following format:
{
'property_name': {'previous': value, 'current': value}
}
For example, if the switch name change from foo to bar, the changes dict will be in the following structure:
{
'name': {'previous': 'foo', 'current': 'bar'}
}
Checks to see if this switch is enabled for the provided input.
If compounded, all switch conditions must be True for the swtich to be enabled. Otherwise, any condition needs to be True for the switch to be enabled.
The switch state is then checked to see if it is GLOBAL or DISABLED. If it is not, then the switch is SELECTIVE and each condition is checked.
Keyword Arguments: inpt – An instance of the Input class.