Class: Flip::DatabaseStrategy
- Inherits:
-
AbstractStrategy
- Object
- AbstractStrategy
- Flip::DatabaseStrategy
- Defined in:
- lib/flip/database_strategy.rb
Instance Method Summary collapse
- #delete!(key) ⇒ Object
- #description ⇒ Object
-
#initialize(model_klass = Feature) ⇒ DatabaseStrategy
constructor
A new instance of DatabaseStrategy.
- #knows?(definition) ⇒ Boolean
- #on?(definition) ⇒ Boolean
- #switch!(key, enable) ⇒ Object
- #switchable? ⇒ Boolean
Methods inherited from AbstractStrategy
Constructor Details
#initialize(model_klass = Feature) ⇒ DatabaseStrategy
Returns a new instance of DatabaseStrategy.
5 6 7 |
# File 'lib/flip/database_strategy.rb', line 5 def initialize(model_klass = Feature) @klass = model_klass end |
Instance Method Details
#delete!(key) ⇒ Object
31 32 33 |
# File 'lib/flip/database_strategy.rb', line 31 def delete! key @klass.where(key: key.to_s).first.try(:destroy) end |
#description ⇒ Object
9 10 11 |
# File 'lib/flip/database_strategy.rb', line 9 def description "Database backed, applies to all users." end |
#knows?(definition) ⇒ Boolean
13 14 15 |
# File 'lib/flip/database_strategy.rb', line 13 def knows? definition !!feature(definition) end |
#on?(definition) ⇒ Boolean
17 18 19 |
# File 'lib/flip/database_strategy.rb', line 17 def on? definition feature(definition).enabled? end |
#switch!(key, enable) ⇒ Object
25 26 27 28 29 |
# File 'lib/flip/database_strategy.rb', line 25 def switch! key, enable record = @klass.where(key: key.to_s).first_or_initialize record.enabled = enable record.save! end |
#switchable? ⇒ Boolean
21 22 23 |
# File 'lib/flip/database_strategy.rb', line 21 def switchable? true end |