Sha256: 971d3cd8c974b62c03fe3a231d9f80563539499f7bd5b8cfba479f58cf6d2ba7

Contents?: true

Size: 960 Bytes

Versions: 2

Compression:

Stored size: 960 Bytes

Contents

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

module Flipper
  module UI
    module Decorators
      class Feature < SimpleDelegator
        # Public: The feature being decorated.
        alias_method :feature, :__getobj__

        # Public: Returns name titleized.
        def pretty_name
          @pretty_name ||= 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,
            'description' => description,
            'gates' => gates.map { |gate|
              Decorators::Gate.new(gate, gate_values[gate.key]).as_json
            },
          }
        end

        # Private
        def titleize(str)
          str.to_s.split('_').map { |word| word.capitalize }.join(' ')
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flipper-ui-0.2.0.beta2 lib/flipper/ui/decorators/feature.rb
flipper-ui-0.2.0.beta1 lib/flipper/ui/decorators/feature.rb