Class: Flipper::Api::V1::Actions::Features

Inherits:
Action
  • Object
show all
Defined in:
lib/flipper/api/v1/actions/features.rb

Constant Summary

Constants inherited from Action

Action::VALID_REQUEST_METHOD_NAMES

Instance Attribute Summary

Attributes inherited from Action

#flipper, #request

Instance Method Summary collapse

Methods inherited from Action

#halt, #header, #initialize, #json_error_response, #json_response, route, route_match?, route_regex, #run, run, #run_other_action, #status

Constructor Details

This class inherits a constructor from Flipper::Api::Action

Instance Method Details

#getObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/flipper/api/v1/actions/features.rb', line 11

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

#postObject



41
42
43
44
45
46
47
# File 'lib/flipper/api/v1/actions/features.rb', line 41

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