Class: Downgrade::Switch
- Inherits:
-
Object
- Object
- Downgrade::Switch
- Defined in:
- lib/downgrade/switch.rb
Instance Attribute Summary collapse
-
#cache_second ⇒ Object
Returns the value of attribute cache_second.
-
#scope ⇒ Object
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(scope) ⇒ Switch
constructor
A new instance of Switch.
- #is_on? ⇒ Boolean
- #turn_off ⇒ Object
- #turn_on(ttl = 600) ⇒ Object
Constructor Details
#initialize(scope) ⇒ Switch
Returns a new instance of Switch.
5 6 7 8 |
# File 'lib/downgrade/switch.rb', line 5 def initialize(scope) @scope = scope @cache_second = 5 end |
Instance Attribute Details
#cache_second ⇒ Object
Returns the value of attribute cache_second.
3 4 5 |
# File 'lib/downgrade/switch.rb', line 3 def cache_second @cache_second end |
#scope ⇒ Object
Returns the value of attribute scope.
3 4 5 |
# File 'lib/downgrade/switch.rb', line 3 def scope @scope end |
Class Method Details
.cache_store ⇒ Object
31 32 33 |
# File 'lib/downgrade/switch.rb', line 31 def cache_store @cache_store ||= ActiveSupport::Cache::MemoryStore.new end |
Instance Method Details
#is_on? ⇒ Boolean
18 19 20 21 22 |
# 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 |