Last active
December 12, 2020 22:41
-
-
Save triangletodd/f87bbefc430559c54f0ff8796c202b53 to your computer and use it in GitHub Desktop.
Ruby Feature Flipper
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
#!/usr/bin/env ruby | |
require 'redis' | |
require 'flipper' | |
require 'flipper/adapters/redis' | |
class Feature | |
ENABLED = Flipper::Actor.new(true) | |
DISABLED = Flipper::Actor.new(false) | |
def initialize | |
options = {} | |
options[:url] = 'redis://127.0.0.1:6379/1' | |
client = Redis.new(options) | |
adapter = Flipper::Adapters::Redis.new(client) | |
@flipper = Flipper.new(adapter) | |
end | |
def enabled?(key, default) | |
@flipper.enabled?(key, default) | |
rescue Redis::CannotConnectError => e | |
return default.flipper_id | |
end | |
end | |
f = Feature.new() | |
puts f.enabled?(:stats, Feature::ENABLED) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment