class Flipflop::Strategies::ActiveRecordStrategy
Public Class Methods
default_description()
click to toggle source
# 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()
click to toggle source
# 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
new(**options)
click to toggle source
Calls superclass method
Flipflop::Strategies::AbstractStrategy::new
# 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
Public Instance Methods
clear!(feature)
click to toggle source
# File lib/flipflop/strategies/active_record_strategy.rb, line 39 def clear!(feature) find(feature).first.try(:destroy) end
enabled?(feature)
click to toggle source
# File lib/flipflop/strategies/active_record_strategy.rb, line 29 def enabled?(feature) find(feature).first.try(:enabled?) end
switch!(feature, enabled)
click to toggle source
# 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?()
click to toggle source
# File lib/flipflop/strategies/active_record_strategy.rb, line 25 def switchable? true end
Protected Instance Methods
find(feature)
click to toggle source
# File lib/flipflop/strategies/active_record_strategy.rb, line 45 def find(feature) @class.where(key: feature.to_s) end