Sha256: b35a8f5e88c1b7b3a958707e4c125fb2e41926435cd1adc5a7652b3fc86064c3
Contents?: true
Size: 975 Bytes
Versions: 3
Compression:
Stored size: 975 Bytes
Contents
require 'zlib' module Flipper module Gates class PercentageOfActors < Gate # Internal: The name of the gate. Used for instrumentation, etc. def name :percentage_of_actors end # Internal: Name converted to value safe for adapter. def key :percentage_of_actors end def data_type :integer end def enabled?(value) value > 0 end # Internal: Checks if the gate is open for a thing. # # Returns true if gate open for thing, false if not. def open?(context) percentage = context.values[key] if Types::Actor.wrappable?(context.thing) actor = Types::Actor.wrap(context.thing) key = "#{context.feature_name}#{actor.value}" Zlib.crc32(key) % 100 < percentage else false end end def protects?(thing) thing.is_a?(Types::PercentageOfActors) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
flipper-0.10.2 | lib/flipper/gates/percentage_of_actors.rb |
flipper-0.10.1 | lib/flipper/gates/percentage_of_actors.rb |
flipper-0.10.0 | lib/flipper/gates/percentage_of_actors.rb |