flipper-api 0.24.0 → 0.24.1

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: ee54a1b8dbd6fbe6c8569970b9b2c25dfabef58f024ca0b2848717a703b17600
4
- data.tar.gz: 63f01695a63096f006332632f8d6d6d982338a70bdd577c214b15b790074aea4
3
+ metadata.gz: 498a3561809183d8cfdc15aa77c221e80578e220de9b97365df9645ad61e47dc
4
+ data.tar.gz: f4755ea4711c5f4220203d67eaa0518e6f2365a069dc9302cfaac2c48ed5b927
5
5
  SHA512:
6
- metadata.gz: 760626f78c88eacc21d3d9e672f82449678bd57014c99f949539d3b4fae0202e7e774df0992118aa2b6d6d3d9bf79883c8558c872356ad1d08d7370d49e008b7
7
- data.tar.gz: f386ad25a8911ce18b7560cd77aed907cc2bd50ae27d05b778058e013d8b3ab68cb6b38919a210baf0c1abd429fd9a57ed44a674c91079415ced685f1b064b43
6
+ metadata.gz: dcc285c9297786310f91250503b37e521accb20c67cdab671326824bcad5ea870fc0e89b6828e57adfb9a7189be592908cb70e20aed014d4d2862fa5e8e31962
7
+ data.tar.gz: 4721e66c96afb93ace4361cc4955b731ab246d7d37a2432ef7d392a8ac738202950f60ca9dd25e3cd1b14d2ffd4ea5f44524ac2e1877e3000d0957d3ee9d7cdc
@@ -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.24.0'.freeze
2
+ VERSION = '0.24.1'.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.24.0
4
+ version: 0.24.1
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-02-17 00:00:00.000000000 Z
11
+ date: 2022-04-13 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.24.0
39
+ version: 0.24.1
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.24.0
46
+ version: 0.24.1
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