Sha256: c05521f93b592949c14ac19775c25793238997d3f9b7ef64d547499846513118
Contents?: true
Size: 939 Bytes
Versions: 4
Compression:
Stored size: 939 Bytes
Contents
module Flipflop module Strategies class ActiveRecordStrategy < AbstractStrategy class << self def default_description "Stores features in database. Applies to all users." end end def initialize(**options) @class = options.delete(:class) || ::Flipflop::Feature if !@class.kind_of?(Class) @class = ActiveSupport::Inflector.constantize(@class.to_s) end super(**options) end def switchable? true end def enabled?(feature) find(feature).first.try(:enabled?) end def switch!(feature, enabled) record = find(feature).first_or_initialize record.enabled = enabled record.save! end def clear!(feature) find(feature).first.try(:destroy) end protected def find(feature) @class.where(key: feature.to_s) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems