class Downgrade::Switch
Attributes
cache_second[RW]
scope[RW]
Public Class Methods
new(scope)
click to toggle source
# File lib/downgrade/switch.rb, line 5 def initialize(scope) @scope = scope @cache_second = 5 end
Private Class Methods
cache_store()
click to toggle source
# File lib/downgrade/switch.rb, line 31 def cache_store @cache_store ||= ActiveSupport::Cache::MemoryStore.new end
Public Instance Methods
is_on?()
click to toggle source
# File lib/downgrade/switch.rb, line 18 def is_on? Downgrade::Switch.cache_store.fetch(cache_key, expires_in: self.cache_second) do Downgrade.redis.get(cache_key).present? end end
turn_off()
click to toggle source
# File lib/downgrade/switch.rb, line 14 def turn_off Downgrade.redis.del(cache_key) end
turn_on(ttl = 600)
click to toggle source
# File lib/downgrade/switch.rb, line 10 def turn_on(ttl = 600) Downgrade.redis.set(cache_key, 1, ex: ttl) end
Private Instance Methods
cache_key()
click to toggle source
# File lib/downgrade/switch.rb, line 26 def cache_key "downgrade:switch:#{scope}" end