class FeatureSetting::FsFeature
Constants
- FEATURES
Public Class Methods
cache_features!()
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 44 def cache_features! features.each do |key, value| create_feature(key, value) value = find_by(key: key, klass: klass).enabled define_checker_method(key) { value } define_enabler_method(key) { false } define_disabler_method(key) { false } end end
define_checker_method(key, &block)
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 54 def define_checker_method(key, &block) unless block_given? block = proc do find_by(key: key, klass: klass)&.enabled ? true : false end end define_singleton_method("#{key}_enabled?") { block.call } end
define_disabler_method(key, &block)
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 72 def define_disabler_method(key, &block) unless block_given? block = proc do disable!(key) end end define_singleton_method("disable_#{key}!") { block.call } end
define_enabler_method(key, &block)
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 63 def define_enabler_method(key, &block) unless block_given? block = proc do enable!(key) end end define_singleton_method("enable_#{key}!") { block.call } end
defined_features()
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 103 def defined_features features.keys.map(&:to_s) end
disable!(key)
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 96 def disable!(key) return unless features.key?(key.to_sym) record = find_by(key: key, klass: klass) record.update(enabled: false) end
enable!(key)
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 89 def enable!(key) return unless features.key?(key.to_sym) record = find_by(key: key, klass: klass) record.update(enabled: true) end
features()
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 26 def features new.features end
init_features!(remove_old_features: false)
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 34 def init_features!(remove_old_features: false) features.each do |key, value| create_feature(key, value) define_checker_method(key) define_enabler_method(key) define_disabler_method(key) end remove_old_features! if remove_old_features end
klass()
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 30 def klass new.klass.to_s end
method_missing(_method, *_args)
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 18 def method_missing(_method, *_args) false end
remove_old_features!()
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 81 def remove_old_features! where(key: all_stored_features - defined_features).destroy_all end
reset_features!()
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 85 def reset_features! init_features! if where(klass: klass).delete_all end
respond_to_missing?(*_args)
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 22 def respond_to_missing?(*_args) true end
Private Class Methods
all_stored_features()
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 109 def all_stored_features all.pluck(:key) end
create_feature(key, value)
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 113 def create_feature(key, value) create_with( key: key, enabled: value, klass: klass ).find_or_create_by( klass: klass, key: key ) end
Public Instance Methods
features()
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 9 def features self.class::FEATURES end
klass()
click to toggle source
# File lib/feature_setting/orm/active_record/fs_feature.rb, line 13 def klass self.class end