Sha256: aa390d747af746381c786189b15a0ea79105504ec2f77cb976efd440b3c5e12a
Contents?: true
Size: 973 Bytes
Versions: 5
Compression:
Stored size: 973 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) id = "#{context.feature_name}#{actor.value}" Zlib.crc32(id) % 100 < percentage else false end end def protects?(thing) thing.is_a?(Types::PercentageOfActors) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems