Class: Flipper::Gates::Group

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

Constant Summary

Constants inherited from Flipper::Gate

Flipper::Gate::InstrumentationName

Instance Attribute Summary

Attributes inherited from Flipper::Gate

#feature_name, #instrumenter

Instance Method Summary collapse

Methods inherited from Flipper::Gate

#disable, #enable, #initialize, #inspect, #instrument, #wrap

Constructor Details

This class inherits a constructor from Flipper::Gate

Instance Method Details

#data_typeObject



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

def data_type
  :set
end

#description(value) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/flipper/gates/group.rb', line 18

def description(value)
  if enabled?(value)
    group_names = value.to_a.sort.map { |name| name.to_sym.inspect }
    "groups (#{group_names.join(', ')})"
  else
    'disabled'
  end
end

#enabled?(value) ⇒ Boolean

Returns:



27
28
29
# File 'lib/flipper/gates/group.rb', line 27

def enabled?(value)
  !value.nil? && !value.empty?
end

#keyObject

Internal: Name converted to value safe for adapter.



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

def key
  :groups
end

#nameObject

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



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

def name
  :group
end

#open?(thing, value) ⇒ Boolean

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

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

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/flipper/gates/group.rb', line 34

def open?(thing, value)
  instrument(:open?, thing) { |payload|
    if thing.nil?
      false
    else
      value.any? { |name|
        begin
          group = Flipper.group(name)
          group.match?(thing)
        rescue GroupNotRegistered
          false
        end
      }
    end
  }
end

#protects?(thing) ⇒ Boolean

Returns:



51
52
53
# File 'lib/flipper/gates/group.rb', line 51

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