Class: Flipper::Gates::PercentageOfTime

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

Instance Method Summary collapse

Methods inherited from Flipper::Gate

#initialize, #inspect, #wrap

Constructor Details

This class inherits a constructor from Flipper::Gate

Instance Method Details

#data_typeObject



14
15
16
# File 'lib/flipper/gates/percentage_of_time.rb', line 14

def data_type
  :integer
end

#enabled?(value) ⇒ Boolean

Returns:



18
19
20
# File 'lib/flipper/gates/percentage_of_time.rb', line 18

def enabled?(value)
  Typecast.to_integer(value) > 0
end

#keyObject

Internal: Name converted to value safe for adapter.



10
11
12
# File 'lib/flipper/gates/percentage_of_time.rb', line 10

def key
  :percentage_of_time
end

#nameObject

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



5
6
7
# File 'lib/flipper/gates/percentage_of_time.rb', line 5

def name
  :percentage_of_time
end

#open?(thing, value, options = {}) ⇒ Boolean

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

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

Returns:



25
26
27
28
# File 'lib/flipper/gates/percentage_of_time.rb', line 25

def open?(thing, value, options = {})
  percentage = Typecast.to_integer(value)
  rand < (percentage / 100.0)
end

#protects?(thing) ⇒ Boolean

Returns:



30
31
32
# File 'lib/flipper/gates/percentage_of_time.rb', line 30

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