Class: Flipflop::Strategies::ActiveRecordStrategy
Instance Attribute Summary
#description, #key, #name, #title
Class Method Summary
collapse
Instance Method Summary
collapse
default_name, #hidden?, #reset!
Constructor Details
Returns a new instance of ActiveRecordStrategy.
17
18
19
20
21
22
23
|
# File 'lib/flipflop/strategies/active_record_strategy.rb', line 17
def initialize(**options)
@class = options.delete(:class) || self.class.define_feature_class
if !@class.kind_of?(Class)
@class = ActiveSupport::Inflector.constantize(@class.to_s)
end
super(**options)
end
|
Class Method Details
.default_description ⇒ Object
5
6
7
|
# File 'lib/flipflop/strategies/active_record_strategy.rb', line 5
def default_description
"Stores features in database. Applies to all users."
end
|
.define_feature_class ⇒ Object
9
10
11
12
13
14
|
# File 'lib/flipflop/strategies/active_record_strategy.rb', line 9
def define_feature_class
return Flipflop::Feature if defined?(Flipflop::Feature)
model = Class.new(ActiveRecord::Base)
Flipflop.const_set(:Feature, model)
end
|
Instance Method Details
#clear!(feature) ⇒ Object
39
40
41
|
# File 'lib/flipflop/strategies/active_record_strategy.rb', line 39
def clear!(feature)
find(feature).first.try(:destroy)
end
|
#enabled?(feature) ⇒ Boolean
29
30
31
|
# File 'lib/flipflop/strategies/active_record_strategy.rb', line 29
def enabled?(feature)
find(feature).first.try(:enabled?)
end
|
#switch!(feature, enabled) ⇒ Object
33
34
35
36
37
|
# File 'lib/flipflop/strategies/active_record_strategy.rb', line 33
def switch!(feature, enabled)
record = find(feature).first_or_initialize
record.enabled = enabled
record.save!
end
|
#switchable? ⇒ Boolean
25
26
27
|
# File 'lib/flipflop/strategies/active_record_strategy.rb', line 25
def switchable?
true
end
|