Skip to content

Instantly share code, notes, and snippets.

@triangletodd
Last active December 12, 2020 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triangletodd/f87bbefc430559c54f0ff8796c202b53 to your computer and use it in GitHub Desktop.
Save triangletodd/f87bbefc430559c54f0ff8796c202b53 to your computer and use it in GitHub Desktop.
Ruby Feature Flipper
#!/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