Created
May 9, 2018 10:30
-
-
Save jsmolina/78887606a16e748e487aa2311c2d2649 to your computer and use it in GitHub Desktop.
Example of feature enable/disable in gutter
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
from distutils.version import StrictVersion | |
class User(object): | |
def __init__(self, version='2.0.0'): | |
self.app_version = version | |
class UserArgument(User): | |
COMPATIBLE_TYPE=User | |
def __init__(self, input): | |
self.applies = 1 | |
self.input = input | |
super(UserArgument, self).__init__(input.app_version) | |
def gutter_example(): | |
from gutter.client.default import gutter | |
from gutter.client.settings import manager as manager_settings | |
from durabledict import RedisDict | |
from redis import Redis | |
from gutter.client.models import Switch, Condition | |
from gutter.client.operators.comparable import MoreThan | |
manager_settings.storage_engine = RedisDict(keyspace='gutter', connection=Redis()) | |
manager_settings.autocreate = True | |
condition = Condition( | |
argument=UserArgument, | |
attribute='app_version', | |
operator=MoreThan(lower_limit=StrictVersion('1.2.1'))) | |
switch = Switch('cool_feature', state=2) | |
switch.conditions.append(condition) | |
gutter.register(switch) | |
user1 = User('2.0.0') | |
print "Is active? {0}".format(gutter.active('cool_feature', user1)) | |
user2 = User('1.0.0') | |
print "Is active? {0}".format(gutter.active('cool_feature', user2)) | |
if __name__ == "__main__": | |
gutter_example() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment