flipper-api 0.23.1 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 416150892b81d4ee93b5e524ae179386f7d6b6de297f199f8e9ae9a1195ff864
4
- data.tar.gz: 5a8eb77ca19843457f681305d1c444bce7d782687d26faeec563a23292a4c995
3
+ metadata.gz: a6fc51e82446b1d30b12dc8efe5441742d845b0aefc6c04bf0a69a21752b7485
4
+ data.tar.gz: 39099982047dd1b9ec6459f42dddbece3661981b81259612e3ca8028d79859e2
5
5
  SHA512:
6
- metadata.gz: 8b359d5d6fb420cd21037ecd5c776ec4b415daeddd70f5af01f5443fa2a75e707415638ea85e5b3cd624182ff12214383b00101bdd10d4d221285515e4697d98
7
- data.tar.gz: 868cfc5fd0d80fc4f9d3a790e414c15ce083e6025747e30731a8267f161aa1f0d761ebbc241530da088dc9115d409b224b57e598ac4b45c421b90f38d0c369b0
6
+ metadata.gz: a95a27f7794f22b0fbd26007b043a7b31b488b4e50d915074c7ce470e32605c7e6ae6f4928f0ffb9a45b81b78fb354e5ed4d6c11bfc4458bd4dbd57221ed623a
7
+ data.tar.gz: 64df3f4d179fb84efa94e2f9ba1936204a4a6e3cf03c8c23d72912bcd02ad36d1820ff22b7f7d4d9d9fb10343af86c427a380dc519ed8cec00ba8257d52f802f
@@ -12,8 +12,9 @@ module Flipper
12
12
 
13
13
  def get
14
14
  return json_error_response(:feature_not_found) unless feature_exists?(feature_name)
15
+ exclude_gates = params['exclude_gates']&.downcase == "true"
15
16
  feature = Decorators::Feature.new(flipper[feature_name])
16
- json_response(feature.as_json)
17
+ json_response(feature.as_json(exclude_gates: exclude_gates))
17
18
  end
18
19
 
19
20
  def delete
@@ -10,6 +10,7 @@ module Flipper
10
10
 
11
11
  def get
12
12
  keys = params['keys']
13
+ exclude_gates = params['exclude_gates']&.downcase == "true"
13
14
  features = if keys
14
15
  names = keys.split(',')
15
16
  if names.empty?
@@ -26,7 +27,7 @@ module Flipper
26
27
  end
27
28
 
28
29
  decorated_features = features.map do |feature|
29
- Decorators::Feature.new(feature).as_json
30
+ Decorators::Feature.new(feature).as_json(exclude_gates: exclude_gates)
30
31
  end
31
32
 
32
33
  json_response(features: decorated_features)
@@ -10,17 +10,20 @@ module Flipper
10
10
  alias_method :feature, :__getobj__
11
11
 
12
12
  # Public: Returns instance as hash that is ready to be json dumped.
13
- def as_json
14
- gate_values = feature.adapter.get(self)
15
- gates_json = gates.map do |gate|
16
- Decorators::Gate.new(gate, gate_values[gate.key]).as_json
17
- end
18
-
19
- {
13
+ def as_json(exclude_gates: false)
14
+ result = {
20
15
  'key' => key,
21
16
  'state' => state.to_s,
22
- 'gates' => gates_json,
23
17
  }
18
+
19
+ unless exclude_gates
20
+ gate_values = feature.adapter.get(self)
21
+ result['gates'] = gates.map do |gate|
22
+ Decorators::Gate.new(gate, gate_values[gate.key]).as_json
23
+ end
24
+ end
25
+
26
+ result
24
27
  end
25
28
  end
26
29
  end
data/lib/flipper/api.rb CHANGED
@@ -17,8 +17,9 @@ module Flipper
17
17
  builder.use Flipper::Api::Middleware, env_key: env_key
18
18
  builder.run app
19
19
  klass = self
20
- builder.define_singleton_method(:inspect) { klass.inspect } # pretty rake routes output
21
- builder
20
+ app = builder.to_app
21
+ app.define_singleton_method(:inspect) { klass.inspect } # pretty rake routes output
22
+ app
22
23
  end
23
24
  end
24
25
  end
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.23.1'.freeze
2
+ VERSION = '0.25.0'.freeze
3
3
  end
@@ -0,0 +1,27 @@
1
+ RSpec.describe Flipper::Api::V1::Decorators::Feature do
2
+ describe "#as_json" do
3
+ context "with exclude_gates set to true" do
4
+ subject { described_class.new(flipper[:my_feature]).as_json(exclude_gates: true) }
5
+
6
+ it "returns json WITHOUT feature gate data" do
7
+ expect(subject.keys).to_not include("gates")
8
+ end
9
+ end
10
+
11
+ context "with exclude_gates set to false" do
12
+ subject { described_class.new(flipper[:my_feature]).as_json(exclude_gates: false) }
13
+
14
+ it "returns json WITH feature gate data" do
15
+ expect(subject.keys).to include("gates")
16
+ end
17
+ end
18
+
19
+ context "without exclude_gates set" do
20
+ subject { described_class.new(flipper[:my_feature]).as_json }
21
+
22
+ it "returns json WITH feature gate data" do
23
+ expect(subject.keys).to include("gates")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -107,7 +107,7 @@ RSpec.describe Flipper::Api do
107
107
 
108
108
  describe 'Inspecting the built Rack app' do
109
109
  it 'returns a String' do
110
- expect(build_api(flipper).inspect).to be_a(String)
110
+ expect(build_api(flipper).inspect).to eq("Flipper::Api")
111
111
  end
112
112
  end
113
113
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipper-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.1
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-19 00:00:00.000000000 Z
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.23.1
39
+ version: 0.25.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.23.1
46
+ version: 0.25.0
47
47
  description:
48
48
  email:
49
49
  - nunemaker@gmail.com
@@ -84,6 +84,7 @@ files:
84
84
  - spec/flipper/api/v1/actions/groups_gate_spec.rb
85
85
  - spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb
86
86
  - spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb
87
+ - spec/flipper/api/v1/decorators/feature_spec.rb
87
88
  - spec/flipper/api_spec.rb
88
89
  homepage: https://github.com/jnunemaker/flipper
89
90
  licenses:
@@ -121,4 +122,5 @@ test_files:
121
122
  - spec/flipper/api/v1/actions/groups_gate_spec.rb
122
123
  - spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb
123
124
  - spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb
125
+ - spec/flipper/api/v1/decorators/feature_spec.rb
124
126
  - spec/flipper/api_spec.rb