class Toggleable::FeatureToggler
Toggleable::FeatureToggler
provides an instance to manage all toggleable keys.
Attributes
features[R]
Public Class Methods
new()
click to toggle source
# File lib/toggleable/feature_toggler.rb, line 12 def initialize @features = [] end
Public Instance Methods
available_features(memoize: Toggleable.configuration.use_memoization)
click to toggle source
# File lib/toggleable/feature_toggler.rb, line 20 def available_features(memoize: Toggleable.configuration.use_memoization) available_features = memoize ? memoized_keys : keys available_features.slice(*features) end
mass_toggle!(mapping, actor: nil)
click to toggle source
# File lib/toggleable/feature_toggler.rb, line 25 def mass_toggle!(mapping, actor: nil) log_changes(mapping, actor) if Toggleable.configuration.logger Toggleable.configuration.storage.mass_set(mapping, namespace: Toggleable.configuration.namespace) end
register(key)
click to toggle source
# File lib/toggleable/feature_toggler.rb, line 16 def register(key) features << key end
Private Instance Methods
keys()
click to toggle source
# File lib/toggleable/feature_toggler.rb, line 32 def keys Toggleable.configuration.storage.get_all(namespace: Toggleable.configuration.namespace) end
log_changes(mapping, actor)
click to toggle source
# File lib/toggleable/feature_toggler.rb, line 46 def log_changes(mapping, actor) previous_values = available_features mapping.each do |key, val| next if previous_values[key].to_s == val.to_s Toggleable.configuration.logger.log(key: key, value: val, actor: actor) end end
memoized_keys()
click to toggle source
# File lib/toggleable/feature_toggler.rb, line 36 def memoized_keys return @_memoized_keys if defined?(@_memoized_keys) && !read_expired? @_last_read_at = Time.now.localtime @_memoized_keys = Toggleable.configuration.storage.get_all(namespace: Toggleable.configuration.namespace) end
read_expired?()
click to toggle source
# File lib/toggleable/feature_toggler.rb, line 42 def read_expired? @_last_read_at < Time.now.localtime - Toggleable.configuration.expiration_time end