Sha256: d315505da7be9834d81eb9235d9c49ebe4ef1cfc73a2de36a689e06e26f18606

Contents?: true

Size: 418 Bytes

Versions: 5

Compression:

Stored size: 418 Bytes

Contents

module Flipper
  module Gates
    class PercentageOfRandom < Gate
      Key = :perc_time

      def type_key
        Key
      end

      def open?(actor)
        percentage = toggle.value

        if percentage.nil?
          false
        else
          rand < (percentage / 100.0)
        end
      end

      def protects?(thing)
        thing.is_a?(Flipper::Types::PercentageOfRandom)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flipper-0.3.0 lib/flipper/gates/percentage_of_random.rb
flipper-0.2.1 lib/flipper/gates/percentage_of_random.rb
flipper-0.2.0 lib/flipper/gates/percentage_of_random.rb
flipper-0.1.1 lib/flipper/gates/percentage_of_random.rb
flipper-0.1.0 lib/flipper/gates/percentage_of_random.rb