class Flipper::Gates::PercentageOfTime

Public Instance Methods

data_type() click to toggle source
# File lib/flipper/gates/percentage_of_time.rb, line 14
def data_type
  :integer
end
enabled?(value) click to toggle source
# File lib/flipper/gates/percentage_of_time.rb, line 18
def enabled?(value)
  value > 0
end
key() click to toggle source

Internal: Name converted to value safe for adapter.

# File lib/flipper/gates/percentage_of_time.rb, line 10
def key
  :percentage_of_time
end
name() click to toggle source

Internal: The name of the gate. Used for instrumentation, etc.

# File lib/flipper/gates/percentage_of_time.rb, line 5
def name
  :percentage_of_time
end
open?(context) click to toggle source

Internal: Checks if the gate is open for a thing.

Returns true if gate open for thing, false if not.

# File lib/flipper/gates/percentage_of_time.rb, line 25
def open?(context)
  value = context.values[key]
  rand < (value / 100.0)
end
protects?(thing) click to toggle source
# File lib/flipper/gates/percentage_of_time.rb, line 30
def protects?(thing)
  thing.is_a?(Flipper::Types::PercentageOfTime)
end