Skip to content

Instantly share code, notes, and snippets.

@simonw
Created August 25, 2015 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonw/fe24758774d45ece0cf6 to your computer and use it in GitHub Desktop.
Save simonw/fe24758774d45ece0cf6 to your computer and use it in GitHub Desktop.
How Gargoyle exclude conditions work
  • If any single exclude condition is a match, the flag is off (no matter what else)
  • If any of the conditions match, the flag is on
  • If any of the exclude conditions do not match, the flag is on

From a very careful read of:

https://github.com/disqus/gargoyle/blob/69568050bd0c4857e3a5d527e4bf0fbf95e3b129/gargoyle/conditions.py#L273-L292

def is_active(self, instance, conditions):
    """
    Given an instance, and the conditions active for this switch, returns
    a boolean representing if the feature is active.
    """
    return_value = None
    for name, field in self.fields.iteritems():
        field_conditions = conditions.get(self.get_namespace(), {}).get(name)
        if field_conditions:
            value = self.get_field_value(instance, name)
            for status, condition in field_conditions:
                exclude = status == EXCLUDE
                if field.is_active(condition, value):
                    if exclude:
                        return False
                    return_value = True
                else:
                    if exclude:
                        return_value = True
    return return_value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment