Sha256: e92bc6a5136d3e24376652aa1e534660b38aad086afade9ccd79f2d0af7564b0

Contents?: true

Size: 725 Bytes

Versions: 5

Compression:

Stored size: 725 Bytes

Contents

module Flipper
  module Gates
    class PercentageOfTime < Gate
      # Internal: The name of the gate. Used for instrumentation, etc.
      def name
        :percentage_of_time
      end

      # Internal: Name converted to value safe for adapter.
      def key
        :percentage_of_time
      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?(thing, value, options = {})
        rand < (value / 100.0)
      end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flipper-0.9.2 lib/flipper/gates/percentage_of_time.rb
flipper-0.9.1 lib/flipper/gates/percentage_of_time.rb
flipper-0.9.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.9.0.beta1 lib/flipper/gates/percentage_of_time.rb
flipper-0.8.0 lib/flipper/gates/percentage_of_time.rb