class Flipper::Gates::PercentageOfActors

Public Instance Methods

data_type() click to toggle source
# File lib/flipper/gates/percentage_of_actors.rb, line 16
def data_type
  :integer
end
enabled?(value) click to toggle source
# File lib/flipper/gates/percentage_of_actors.rb, line 20
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_actors.rb, line 12
def key
  :percentage_of_actors
end
name() click to toggle source

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

# File lib/flipper/gates/percentage_of_actors.rb, line 7
def name
  :percentage_of_actors
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_actors.rb, line 27
def open?(context)
  percentage = context.values[key]

  if Types::Actor.wrappable?(context.thing)
    actor = Types::Actor.wrap(context.thing)
    id = "#{context.feature_name}#{actor.value}"
    # this is to support up to 3 decimal places in percentages
    scaling_factor = 1_000
    Zlib.crc32(id) % (100 * scaling_factor) < percentage * scaling_factor
  else
    false
  end
end
protects?(thing) click to toggle source
# File lib/flipper/gates/percentage_of_actors.rb, line 41
def protects?(thing)
  thing.is_a?(Types::PercentageOfActors)
end