module Flipper::Adapter
Adding a module include so we have some hooks for stuff down the road
Public Class Methods
included(base)
click to toggle source
# File lib/flipper/adapter.rb, line 4 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
default_config()
click to toggle source
Public: Default config for a feature's gate values.
# File lib/flipper/adapter.rb, line 51 def default_config self.class.default_config end
get_all()
click to toggle source
Public: Get all features and gate values in one call. Defaults to one call to features and another to get_multi. Feel free to override per adapter to make this more efficient.
# File lib/flipper/adapter.rb, line 24 def get_all instances = features.map { |key| Flipper::Feature.new(key, self) } get_multi(instances) end
get_multi(features)
click to toggle source
Public: Get multiple features in one call. Defaults to one get per feature. Feel free to override per adapter to make this more efficient and reduce network calls.
# File lib/flipper/adapter.rb, line 32 def get_multi(features) result = {} features.each do |feature| result[feature.key] = get(feature) end result end
import(source_adapter)
click to toggle source
Public: Wipe features and gate values and then import features and gate values from provided adapter.
Returns nothing.
# File lib/flipper/adapter.rb, line 44 def import(source_adapter) wipe copy_features_and_gates(source_adapter) nil end
Private Instance Methods
copy_features_and_gates(source_adapter)
click to toggle source
Private: Copy source adapter features and gate values into self.
# File lib/flipper/adapter.rb, line 58 def copy_features_and_gates(source_adapter) source_adapter.features.each do |key| source_feature = Flipper::Feature.new(key, source_adapter) destination_feature = Flipper::Feature.new(key, self) case source_feature.state when :on destination_feature.enable when :conditional source_feature.groups_value.each do |value| destination_feature.enable_group(value) end source_feature.actors_value.each do |value| destination_feature.enable_actor(Flipper::Actor.new(value)) end destination_feature.enable_percentage_of_actors(source_feature.percentage_of_actors_value) destination_feature.enable_percentage_of_time(source_feature.percentage_of_time_value) when :off destination_feature.add end end end
wipe()
click to toggle source
Private: Completely wipe adapter features and gate values.
# File lib/flipper/adapter.rb, line 84 def wipe features.each do |key| feature = Flipper::Feature.new(key, self) remove(feature) end end