Sha256: 693106a146afe28eb16d0977c58be67b28342f1fe03c5bc667180cd3f75b9953
Contents?: true
Size: 1.61 KB
Versions: 18
Compression:
Stored size: 1.61 KB
Contents
require 'flipper/api/action' require 'flipper/api/v1/decorators/feature' module Flipper module Api module V1 module Actions class Features < Api::Action route %r{\A/features/?\Z} def get keys = params['keys'] exclude_gates = params['exclude_gates']&.downcase == "true" exclude_gate_names = params['exclude_gate_names']&.downcase == "true" features = if keys names = keys.split(',') if names.empty? [] else existing_feature_names = names.keep_if do |feature_name| feature_exists?(feature_name) end flipper.preload(existing_feature_names) end else flipper.features end decorated_features = features.map do |feature| Decorators::Feature.new(feature).as_json( exclude_gates: exclude_gates, exclude_gate_names: exclude_gate_names ) end json_response(features: decorated_features) end def post feature_name = params.fetch('name') { json_error_response(:name_invalid) } feature = flipper[feature_name] feature.add decorated_feature = Decorators::Feature.new(feature) json_response(decorated_feature.as_json, 200) end private def feature_exists?(feature_name) flipper.features.map(&:key).include?(feature_name) end end end end end end
Version data entries
18 entries across 18 versions & 1 rubygems