class Flipper::Api::V1::Actions::Features

Public Instance Methods

get() click to toggle source
# File lib/flipper/api/v1/actions/features.rb, line 11
def get
  keys = params['keys']
  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
  end

  json_response(features: decorated_features)
end
post() click to toggle source
# File lib/flipper/api/v1/actions/features.rb, line 35
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 Instance Methods

feature_exists?(feature_name) click to toggle source
# File lib/flipper/api/v1/actions/features.rb, line 45
def feature_exists?(feature_name)
  flipper.features.map(&:key).include?(feature_name)
end