class Flipper::UI::Decorators::Feature

Constants

StateSortMap

Attributes

description[RW]

Internal: Used to preload description if descriptions_source is configured for Flipper::UI.

Public Instance Methods

<=>(other) click to toggle source
# File lib/flipper/ui/decorators/feature.rb, line 79
def <=>(other)
  if state == other.state
    key <=> other.key
  else
    StateSortMap[state] <=> StateSortMap[other.state]
  end
end
color_class() click to toggle source
# File lib/flipper/ui/decorators/feature.rb, line 23
def color_class
  case feature.state
  when :on
    'bg-success'
  when :off
    'bg-danger'
  when :conditional
    'bg-warning'
  end
end
gate_state_title() click to toggle source
# File lib/flipper/ui/decorators/feature.rb, line 58
def gate_state_title
  case feature.state
  when :on
    "Fully enabled"
  when :conditional
    "Conditionally enabled"
  else
    "Disabled"
  end
end
gates_in_words() click to toggle source
# File lib/flipper/ui/decorators/feature.rb, line 34
def gates_in_words
  return "Fully Enabled" if feature.boolean_value

  statuses = []

  if feature.actors_value.count > 0
    statuses << %Q(<span data-toggle="tooltip" data-placement="bottom" title="#{Util.to_sentence(feature.actors_value.to_a)}">) + Util.pluralize(feature.actors_value.count, 'actor', 'actors') + "</span>"
  end

  if feature.groups_value.count > 0
    statuses << %Q(<span data-toggle="tooltip" data-placement="bottom" title="#{Util.to_sentence(feature.groups_value.to_a)}">) + Util.pluralize(feature.groups_value.count, 'group', 'groups') + "</span>"
  end

  if feature.percentage_of_actors_value > 0
    statuses << "#{feature.percentage_of_actors_value}% of actors"
  end

  if feature.percentage_of_time_value > 0
    statuses << "#{feature.percentage_of_time_value}% of time"
  end

  Util.to_sentence(statuses)
end
pretty_enabled_gate_names() click to toggle source
# File lib/flipper/ui/decorators/feature.rb, line 69
def pretty_enabled_gate_names
  enabled_gates.map { |gate| Util.titleize(gate.key) }.sort.join(', ')
end
pretty_name() click to toggle source

Public: Returns name titleized.

# File lib/flipper/ui/decorators/feature.rb, line 19
def pretty_name
  @pretty_name ||= Util.titleize(name)
end