Welcome to gutter’s documentation!

Contents:

gutter.models

copyright:
  1. 2010-2012 DISQUS.
license:

Apache License 2.0, see LICENSE for more details.

class gutter.client.models.Condition(argument, attribute, operator, negative=False)[source]

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:

  1. 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.
  2. You would then create a new Condition via: Condition(argument=UserInput, attriibute='age', operator=Between(15, 30)).
  3. 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.
call(inpt)[source]

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.

class gutter.client.models.Manager(storage, autocreate=False, switch_class=<class 'gutter.client.models.Switch'>, inputs=None, namespace=None)[source]

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.

NONE_INPUT = <object object at 0x10f486750>

Special singleton used to represent a “no input” which arguments can look for and ignore

register(switch, signal=<gutter.client.signals.Signal object at 0x11065f190>)[source]

Register a switch and persist it to the storage.

switch(name)[source]

Returns the switch with the provided name.

If autocreate is set to True and no switch with that name exists, a DISABLED switch will be with that name.

Keyword Arguments: name – A name of a switch.

switches None[source]

List of all switches currently registered.

class gutter.client.models.Switch(name, state=1, compounded=False, parent=None, concent=True, manager=None, label=None, description=None)[source]

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.

changed None[source]

Boolean of if the switch has changed since last saved.

changes None[source]

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'}
}
enabled_for(inpt)[source]

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.

reset()[source]

Resets switch change tracking.

No switch properties are alterted, only the tracking of what has changed is reset.

save()[source]

Saves this switch in its manager (if present).

Equivilant to self.manager.update(self). If no manager is set for the switch, this method is a no-op.

Indices and tables

Table Of Contents

This Page