Class: Flipper::Gates::Actor

Inherits:
Flipper::Gate show all
Defined in:
lib/flipper/gates/actor.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, #enabled?, #initialize, #inspect, #instrument, #toggle

Constructor Details

This class inherits a constructor from Flipper::Gate

Instance Method Details

#descriptionObject



50
51
52
53
54
55
56
# File 'lib/flipper/gates/actor.rb', line 50

def description
  if enabled?
    "actors (#{toggle.value.to_a.sort.join(', ')})"
  else
    'disabled'
  end
end

#disable(thing) ⇒ Object



46
47
48
# File 'lib/flipper/gates/actor.rb', line 46

def disable(thing)
  super Types::Actor.wrap(thing)
end

#enable(thing) ⇒ Object



42
43
44
# File 'lib/flipper/gates/actor.rb', line 42

def enable(thing)
  super Types::Actor.wrap(thing)
end

#keyObject

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



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

def key
  :actors
end

#nameObject

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



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

def name
  :actor
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:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/flipper/gates/actor.rb', line 22

def open?(thing)
  instrument(:open?, thing) { |payload|
    if thing.nil?
      false
    else
      if Types::Actor.wrappable?(thing)
        actor = Types::Actor.wrap(thing)
        enabled_actor_ids = toggle.value
        enabled_actor_ids.include?(actor.value)
      else
        false
      end
    end
  }
end

#protects?(thing) ⇒ Boolean

Returns:



38
39
40
# File 'lib/flipper/gates/actor.rb', line 38

def protects?(thing)
  Types::Actor.wrappable?(thing)
end

#toggle_classObject

Internal: The toggle class used to enable/disable the gate for a thing.



15
16
17
# File 'lib/flipper/gates/actor.rb', line 15

def toggle_class
  Toggles::Set
end