flipper-api 0.24.0 → 0.25.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: 463722a6c76397e004716c02360817a52d22dafda409d5508ec93355783d2f87
4
+ data.tar.gz: c2b457498c463653f8ca0fcf0baf0e118d4c0941316294d0bcf12cc91b90d958
5
5
  SHA512:
6
- metadata.gz: 760626f78c88eacc21d3d9e672f82449678bd57014c99f949539d3b4fae0202e7e774df0992118aa2b6d6d3d9bf79883c8558c872356ad1d08d7370d49e008b7
7
- data.tar.gz: f386ad25a8911ce18b7560cd77aed907cc2bd50ae27d05b778058e013d8b3ab68cb6b38919a210baf0c1abd429fd9a57ed44a674c91079415ced685f1b064b43
6
+ metadata.gz: 7faf36080060780258a8a979fc206a9cdb9ae69df3b3231b30f9b156cb12130f6d7a7ae82fb7d965a578a66d4415bbd649a2b3e67f93073df089c15dcf2548a3
7
+ data.tar.gz: 24ea9e61bb8cda87d3efa602bfacfae9f9d63d9db7b75e7955d7ac8a5afed17a9694f4868c4dd9c7639c02b02928490dfdd67730e81a25fdc368e7eb17721ebc
@@ -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.25.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.25.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-17 00:00:00.000000000 Z
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -36,15 +36,15 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.24.0
39
+ version: 0.25.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
47
- description:
46
+ version: 0.25.1
47
+ description:
48
48
  email:
49
49
  - nunemaker@gmail.com
50
50
  executables: []
@@ -84,13 +84,14 @@ 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:
90
91
  - MIT
91
92
  metadata:
92
93
  changelog_uri: https://github.com/jnunemaker/flipper/blob/master/Changelog.md
93
- post_install_message:
94
+ post_install_message:
94
95
  rdoc_options: []
95
96
  require_paths:
96
97
  - lib
@@ -105,8 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  - !ruby/object:Gem::Version
106
107
  version: '0'
107
108
  requirements: []
108
- rubygems_version: 3.1.2
109
- signing_key:
109
+ rubygems_version: 3.3.7
110
+ signing_key:
110
111
  specification_version: 4
111
112
  summary: API for the Flipper gem
112
113
  test_files:
@@ -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