Class: Flip::DatabaseStrategy

Inherits:
AbstractStrategy show all
Defined in:
lib/flip/database_strategy.rb

Instance Method Summary collapse

Methods inherited from AbstractStrategy

#name

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

#descriptionObject



9
10
11
# File 'lib/flip/database_strategy.rb', line 9

def description
  "Database backed, applies to all users."
end

#knows?(definition) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/flip/database_strategy.rb', line 13

def knows? definition
  !!feature(definition)
end

#on?(definition) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


21
22
23
# File 'lib/flip/database_strategy.rb', line 21

def switchable?
  true
end