1# frozen_string_literal: true 2 3module API 4 module Entities 5 class UnleashFeature < Grape::Entity 6 expose :name 7 expose :description, unless: ->(feature) { feature.description.nil? } 8 expose :active, as: :enabled 9 expose :strategies do |flag| 10 flag.strategies.map do |strategy| 11 if legacy_strategy?(strategy) 12 UnleashLegacyStrategy.represent(strategy) 13 elsif gitlab_user_list_strategy?(strategy) 14 UnleashGitlabUserListStrategy.represent(strategy) 15 else 16 UnleashStrategy.represent(strategy) 17 end 18 end 19 end 20 21 private 22 23 def legacy_strategy?(strategy) 24 !strategy.respond_to?(:name) 25 end 26 27 def gitlab_user_list_strategy?(strategy) 28 strategy.name == ::Operations::FeatureFlags::Strategy::STRATEGY_GITLABUSERLIST 29 end 30 end 31 end 32end 33