Class: Flipper::Gates::PercentageOfActors

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

Constant Summary

Constants inherited from Flipper::Gate

Flipper::Gate::InstrumentationName

Instance Attribute Summary

Attributes inherited from Flipper::Gate

#feature, #instrumenter

Instance Method Summary collapse

Methods inherited from Flipper::Gate

#adapter_key, #disable, #enable, #enabled?, #initialize, #inspect, #instrument, #toggle, #toggle_class

Constructor Details

This class inherits a constructor from Flipper::Gate

Instance Method Details

#descriptionObject



37
38
39
40
41
42
43
# File 'lib/flipper/gates/percentage_of_actors.rb', line 37

def description
  if enabled?
    "#{toggle.value}% of actors"
  else
    'disabled'
  end
end

#keyObject

Internal: The piece of the adapter key that is unique to the gate class.



12
13
14
# File 'lib/flipper/gates/percentage_of_actors.rb', line 12

def key
  :perc_actors
end

#nameObject

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



7
8
9
# File 'lib/flipper/gates/percentage_of_actors.rb', line 7

def name
  :percentage_of_actors
end

#open?(thing) ⇒ Boolean

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

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

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/flipper/gates/percentage_of_actors.rb', line 19

def open?(thing)
  instrument(:open?, thing) { |payload|
    percentage = toggle.value.to_i

    if Types::Actor.wrappable?(thing)
      actor = Types::Actor.wrap(thing)
      key = "#{@feature.name}#{actor.value}"
      Zlib.crc32(key) % 100 < percentage
    else
      false
    end
  }
end

#protects?(thing) ⇒ Boolean

Returns:



33
34
35
# File 'lib/flipper/gates/percentage_of_actors.rb', line 33

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