Sha256: 3594f4fd4af726b149b7424f103ab415c825bbff58a186e416e7404c6bc64e12

Contents?: true

Size: 1.46 KB

Versions: 17

Compression:

Stored size: 1.46 KB

Contents

require 'delegate'
require 'flipper/ui/decorators/gate'
require 'flipper/ui/util'

module Flipper
  module UI
    module Decorators
      class Feature < SimpleDelegator
        include Comparable

        # Public: The feature being decorated.
        alias_method :feature, :__getobj__

        # Public: Returns name titleized.
        def pretty_name
          @pretty_name ||= Util.titleize(name)
        end

        # Public: Returns instance as hash that is ready to be json dumped.
        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

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

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

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

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
flipper-ui-0.10.2 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.10.1 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.10.0 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.9.2 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.9.1 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.9.0 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.9.0.beta1 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.8.0 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.7.5 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.7.4 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.7.3 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.7.2 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.7.1 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.7.0 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.7.0.beta6 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.7.0.beta5 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.7.0.beta4 lib/flipper/ui/decorators/feature.rb