1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
require 'flipper'
module Flipper
module Adapters
class Rollout
include Adapter
class AdapterMethodNotSupportedError < Error
def initialize(message = 'unsupported method called for import adapter')
super(message)
end
end
# Public: The name of the adapter.
attr_reader :name
def initialize(rollout)
@rollout = rollout
@name = :rollout
end
# Public: The set of known features.
def features
@rollout.features
end
# Public: Gets the values for all gates for a given feature.
#
# Returns a Hash of Flipper::Gate#key => value.
def get(feature)
rollout_feature = @rollout.get(feature.key)
return default_config if rollout_feature.nil?
boolean = nil
groups = Set.new(rollout_feature.groups)
actors = Set.new(rollout_feature.users)
percentage_of_actors = case rollout_feature.percentage
when 100
boolean = true
groups = Set.new
actors = Set.new
nil
when 0
nil
else
rollout_feature.percentage
end
{
boolean: boolean,
groups: groups,
actors: actors,
percentage_of_actors: percentage_of_actors,
percentage_of_time: nil,
}
end
def add(_feature)
raise AdapterMethodNotSupportedError
end
def remove(_feature)
raise AdapterMethodNotSupportedError
end
def clear(_feature)
raise AdapterMethodNotSupportedError
end
def enable(_feature, _gate, _thing)
raise AdapterMethodNotSupportedError
end
def disable(_feature, _gate, _thing)
raise AdapterMethodNotSupportedError
end
def import(_source_adapter)
raise AdapterMethodNotSupportedError
end
end
end
end
|