Sha256: 45eb857645513ba23757672088418b5f5474bf6d17a051c5aaa9c66a5372d64a

Contents?: true

Size: 734 Bytes

Versions: 20

Compression:

Stored size: 734 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?(context)
        rand < (context.values.percentage_of_time / 100.0)
      end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
flipper-1.3.2 lib/flipper/gates/percentage_of_time.rb
flipper-1.3.1 lib/flipper/gates/percentage_of_time.rb
flipper-1.3.0 lib/flipper/gates/percentage_of_time.rb
flipper-1.3.0.pre lib/flipper/gates/percentage_of_time.rb
flipper-1.2.2 lib/flipper/gates/percentage_of_time.rb
flipper-1.2.1 lib/flipper/gates/percentage_of_time.rb
flipper-1.2.0 lib/flipper/gates/percentage_of_time.rb
flipper-1.1.2 lib/flipper/gates/percentage_of_time.rb
flipper-1.1.1 lib/flipper/gates/percentage_of_time.rb
flipper-1.1.0 lib/flipper/gates/percentage_of_time.rb
flipper-1.0.0 lib/flipper/gates/percentage_of_time.rb
flipper-1.0.0.pre lib/flipper/gates/percentage_of_time.rb
flipper-0.28.3 lib/flipper/gates/percentage_of_time.rb
flipper-0.28.2 lib/flipper/gates/percentage_of_time.rb
flipper-0.28.1 lib/flipper/gates/percentage_of_time.rb
flipper-0.28.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.27.1 lib/flipper/gates/percentage_of_time.rb
flipper-0.27.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.26.2 lib/flipper/gates/percentage_of_time.rb
flipper-0.26.1 lib/flipper/gates/percentage_of_time.rb