Sha256: 7f6042d7eff92210a4ef3a6580c974ba7ad403721eb4de4f21dbbb8ff2490b5e

Contents?: true

Size: 742 Bytes

Versions: 54

Compression:

Stored size: 742 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)
        value = context.values[key]
        rand < (value / 100.0)
      end

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

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
flipper-0.20.2 lib/flipper/gates/percentage_of_time.rb
flipper-0.20.1 lib/flipper/gates/percentage_of_time.rb
flipper-0.20.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.20.0.beta3 lib/flipper/gates/percentage_of_time.rb
flipper-0.20.0.beta2 lib/flipper/gates/percentage_of_time.rb
flipper-0.20.0.beta1 lib/flipper/gates/percentage_of_time.rb
flipper-0.19.1 lib/flipper/gates/percentage_of_time.rb
flipper-0.19.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.18.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.17.2 lib/flipper/gates/percentage_of_time.rb
flipper-0.17.1 lib/flipper/gates/percentage_of_time.rb
flipper-0.16.2 lib/flipper/gates/percentage_of_time.rb
flipper-0.16.1 lib/flipper/gates/percentage_of_time.rb
flipper-0.16.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.15.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.14.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.13.0 lib/flipper/gates/percentage_of_time.rb
flipper-0.13.0.beta1 lib/flipper/gates/percentage_of_time.rb
flipper-0.12.2 lib/flipper/gates/percentage_of_time.rb
flipper-0.12.1 lib/flipper/gates/percentage_of_time.rb