Class: Flipper::UI::Decorators::Feature

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Comparable
Defined in:
lib/flipper/ui/decorators/feature.rb

Constant Summary collapse

StateSortMap =
{
  :on => 1,
  :conditional => 2,
  :off => 3,
}

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/flipper/ui/decorators/feature.rb', line 53

def <=>(other)
  if state == other.state
    key <=> other.key
  else
    StateSortMap[state] <=> StateSortMap[other.state]
  end
end

#as_jsonObject

Public: Returns instance as hash that is ready to be json dumped.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/flipper/ui/decorators/feature.rb', line 20

def as_json
  gate_values = feature.gate_values
  {
    'id' => name.to_s,
    'name' => pretty_name,
    'state' => state.to_s,
    'gates' => gates.map { |gate|
      Decorators::Gate.new(gate, gate_values[gate.key]).as_json
    },
  }
end

#color_classObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/flipper/ui/decorators/feature.rb', line 32

def color_class
  case feature.state
  when :on
    "text-open"
  when :off
    "text-closed"
  when :conditional
    "text-pending"
  end
end

#pretty_enabled_gate_namesObject



43
44
45
# File 'lib/flipper/ui/decorators/feature.rb', line 43

def pretty_enabled_gate_names
  enabled_gates.map { |gate| Util.titleize(gate.key) }.sort.join(', ')
end

#pretty_nameObject

Public: Returns name titleized.



15
16
17
# File 'lib/flipper/ui/decorators/feature.rb', line 15

def pretty_name
  @pretty_name ||= Util.titleize(name)
end