Sha256: 7827d90c8cf4890867d75681744346d2f20fa74fd216fad7b3ba90929617f038

Contents?: true

Size: 799 Bytes

Versions: 10

Compression:

Stored size: 799 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)
        Typecast.to_integer(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 = {})
        percentage = Typecast.to_integer(value)
        rand < (percentage / 100.0)
      end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
flipper-0.7.5 lib/flipper/gates/percentage_of_time.rb
flipper-0.7.4 lib/flipper/gates/percentage_of_time.rb
flipper-0.7.3 lib/flipper/gates/percentage_of_time.rb
flipper-0.7.2 lib/flipper/gates/percentage_of_time.rb
flipper-0.7.1 lib/flipper/gates/percentage_of_time.rb
flipper-0.7.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.7.0.beta6 lib/flipper/gates/percentage_of_time.rb
flipper-0.7.0.beta5 lib/flipper/gates/percentage_of_time.rb
flipper-0.7.0.beta4 lib/flipper/gates/percentage_of_time.rb
flipper-0.7.0.beta3 lib/flipper/gates/percentage_of_time.rb