class BarsoomUtils::FeatureToggle

Constants

REDIS_KEY

We (counter-intuitively, perhaps) store disabled toggles, so we can assume them to be enabled by default in dev, staging and tests.

Public Class Methods

list() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 34
def self.list
  redis.smembers(REDIS_KEY).sort
end
off?(feature, controller_or_view = nil, redis: self.redis) click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 22
def self.off?(feature, controller_or_view = nil, redis: self.redis)
  new(feature, controller_or_view: controller_or_view, redis: redis).off?
end
on?(feature, controller_or_view = nil, redis: self.redis) click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 18
def self.on?(feature, controller_or_view = nil, redis: self.redis)
  new(feature, controller_or_view: controller_or_view, redis: redis).on?
end
redis() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 14
def self.redis
  @redis || $redis
end
redis=(redis) click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 10
def self.redis=(redis)
  @redis = redis
end
turn_off(feature, redis: self.redis) click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 30
def self.turn_off(feature, redis: self.redis)
  new(feature, redis: redis).turn_off
end
turn_on(feature, redis: self.redis) click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 26
def self.turn_on(feature, redis: self.redis)
  new(feature, redis: redis).turn_on
end

Public Instance Methods

off?() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 48
def off?
  not on?
end
on?() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 40
def on?
  if has_param_override?
    on_according_to_param?
  else
    on_according_to_redis?
  end
end
turn_off() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 52
def turn_off
  redis.sadd REDIS_KEY, feature_name
end
turn_on() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 56
def turn_on
  redis.srem REDIS_KEY, feature_name
end

Private Instance Methods

feature_name() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 79
def feature_name
  @feature_name.to_s
end
has_param_override?() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 62
def has_param_override?
  controller_or_view && controller_or_view.params.has_key?("ft_#{feature_name}")
end
on_according_to_param?() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 66
def on_according_to_param?
  value = controller_or_view && controller_or_view.params["ft_#{feature_name}"]
  value == "true"
end
on_according_to_redis?() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 71
def on_according_to_redis?
  not redis.sismember(REDIS_KEY, feature_name)
end
redis() click to toggle source
# File lib/barsoom_utils/feature_toggle.rb, line 75
def redis
  @redis || self.class.redis
end