Class: Flipper::Gates::PercentageOfRandom

Inherits:
Flipper::Gate show all
Defined in:
lib/flipper/gates/percentage_of_random.rb

Constant Summary collapse

Key =
:perc_time

Constants inherited from Flipper::Gate

Flipper::Gate::Separator

Instance Attribute Summary

Attributes inherited from Flipper::Gate

#feature

Instance Method Summary collapse

Methods inherited from Flipper::Gate

#disable, #enable, #initialize, #key, #key_prefix, #match?, #toggle, #toggle_class

Constructor Details

This class inherits a constructor from Flipper::Gate

Instance Method Details

#open?(actor) ⇒ Boolean

Returns:



10
11
12
13
14
15
16
17
18
# File 'lib/flipper/gates/percentage_of_random.rb', line 10

def open?(actor)
  percentage = toggle.value

  if percentage.nil?
    false
  else
    rand < (percentage / 100.0)
  end
end

#protects?(thing) ⇒ Boolean

Returns:



20
21
22
# File 'lib/flipper/gates/percentage_of_random.rb', line 20

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

#type_keyObject



6
7
8
# File 'lib/flipper/gates/percentage_of_random.rb', line 6

def type_key
  Key
end