Sha256: 01b1125d6d23713e217cecad2e088bd0f4e8a513167d7c5d6a6d23b6e6ba38d3
Contents?: true
Size: 864 Bytes
Versions: 1
Compression:
Stored size: 864 Bytes
Contents
module Flipper module Gates class PercentageOfRandom < Gate # Internal: The name of the gate. Used for instrumentation, etc. def name :percentage_of_random end # Internal: The piece of the adapter key that is unique to the gate class. def key :perc_time end # Internal: Checks if the gate is open for a thing. # # Returns true if gate open for thing, false if not. def open?(thing) instrument(:open?, thing) { |payload| percentage = toggle.value.to_i rand < (percentage / 100.0) } end def protects?(thing) thing.is_a?(Flipper::Types::PercentageOfRandom) end def description if enabled? "#{toggle.value}% of the time" else 'disabled' end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
flipper-0.4.0 | lib/flipper/gates/percentage_of_random.rb |