flipper-api 1.2.2 → 1.3.0.pre

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: 05240b6a191849388e613ed9bfdb792eb2b61a0a45bdd4479dfc5bfad0969d2e
4
- data.tar.gz: 245d149acf46f28f00a784d6f0426be07ae1f37210d701c5f9988d244df2a42f
3
+ metadata.gz: 35faa9238c95b07d1bde406a088808f18b2b7cf915d9c95751e6ebb111d99080
4
+ data.tar.gz: 9ed7baec0b1a6b6ad2dc0458a7989d82c284f80ccd86e6e3f3d7640ed54720a8
5
5
  SHA512:
6
- metadata.gz: 42be6c946efeb2824240035f9a6bb4c19f577cf37d291cfd2e5a2fb9605de6bc2edb15e07a0fa00b74c4680022682f2bd0686b98e52b55b440a4b2b2c32a5ad1
7
- data.tar.gz: c7918dbf6548e111095b1a812e57743a7e72bd4d8ac1ceeae0109c90d0c23db5ae73059dc2871fc752343d3c7f9bae1e52107e3703a19f84348c30f20ae12b3a
6
+ metadata.gz: b3c7a5545c7be59b68e5e56029f4292efa89860bdab7b53ddc123f466d49ed5036739f02fee622fad052ddc529d989173ef0754cbe8435b6f6cd2f6723678596
7
+ data.tar.gz: f206617cd06710e4df31552a98a48ab0fbc04a6056c1406e2f285b418ad6fc8976164fba91f03037ca72350d71800d19f52042fdc5f82081a85157c153b3fa34
@@ -12,6 +12,7 @@ module Flipper
12
12
  CONTENT_TYPE = 'CONTENT_TYPE'.freeze
13
13
  QUERY_STRING = 'QUERY_STRING'.freeze
14
14
  REQUEST_BODY = 'rack.input'.freeze
15
+ REWIND_BODY = Gem::Version.new(Rack.release) < Gem::Version.new('3.0.0')
15
16
 
16
17
  # Public: Merge request body params with query string params
17
18
  # This way can access all params with Rack::Request#params
@@ -21,7 +22,7 @@ module Flipper
21
22
  def call(env)
22
23
  if env[CONTENT_TYPE] == 'application/json'
23
24
  body = env[REQUEST_BODY].read
24
- env[REQUEST_BODY].rewind
25
+ env[REQUEST_BODY].rewind if REWIND_BODY
25
26
  update_params(env, body)
26
27
  end
27
28
  @app.call(env)
@@ -34,6 +34,8 @@ module Flipper
34
34
  def call!(env)
35
35
  request = Rack::Request.new(env)
36
36
  action_class = @action_collection.action_for_request(request)
37
+ env["flipper.action_class"] = action_class
38
+ env["flipper.action_method"] = request.request_method.downcase
37
39
 
38
40
  if action_class.nil?
39
41
  @app.call(env)
@@ -10,8 +10,11 @@ module Flipper
10
10
  route %r{\A/import/?\Z}
11
11
 
12
12
  def post
13
+ # Rack 3 changed the requirement to rewind the body, so we can't assume it is rewound,
14
+ # so rewind before under Rack 3+ and after under Rack 2.
15
+ request.body.rewind if Gem::Version.new(Rack.release) >= Gem::Version.new('3.0.0')
13
16
  body = request.body.read
14
- request.body.rewind
17
+ request.body.rewind if Gem::Version.new(Rack.release) < Gem::Version.new('3.0.0')
15
18
  export = Flipper::Exporters::Json::Export.new(contents: body)
16
19
  flipper.import(export)
17
20
  json_response({}, 204)
@@ -1,3 +1,5 @@
1
+ require 'delegate'
2
+
1
3
  module Flipper
2
4
  module Api
3
5
  module V1
@@ -1,24 +1,24 @@
1
- require 'delegate'
2
1
  require 'flipper/api/v1/decorators/gate'
3
2
 
4
3
  module Flipper
5
4
  module Api
6
5
  module V1
7
6
  module Decorators
8
- class Feature < SimpleDelegator
9
- # Public: The feature being decorated.
10
- alias_method :feature, :__getobj__
7
+ class Feature
8
+ def initialize(feature)
9
+ @feature = feature
10
+ end
11
11
 
12
12
  # Public: Returns instance as hash that is ready to be json dumped.
13
13
  def as_json(exclude_gates: false, exclude_gate_names: false)
14
14
  result = {
15
- 'key' => key,
16
- 'state' => state.to_s,
15
+ 'key' => @feature.key,
16
+ 'state' => @feature.state.to_s,
17
17
  }
18
18
 
19
19
  unless exclude_gates
20
- gate_values = feature.adapter.get(self)
21
- result['gates'] = gates.map do |gate|
20
+ gate_values = @feature.adapter.get(@feature)
21
+ result['gates'] = @feature.gates.map do |gate|
22
22
  Decorators::Gate.new(gate, gate_values[gate.key]).as_json(exclude_name: exclude_gate_names)
23
23
  end
24
24
  end
@@ -2,24 +2,18 @@ module Flipper
2
2
  module Api
3
3
  module V1
4
4
  module Decorators
5
- class Gate < SimpleDelegator
6
- # Public the gate being decorated
7
- alias_method :gate, :__getobj__
8
-
9
- # Public: the value for the gate from the adapter.
10
- attr_reader :value
11
-
5
+ class Gate
12
6
  def initialize(gate, value = nil)
13
- super gate
7
+ @gate = gate
14
8
  @value = value
15
9
  end
16
10
 
17
11
  def as_json(exclude_name: false)
18
12
  as_json = {
19
- 'key' => gate.key.to_s,
13
+ 'key' => @gate.key.to_s,
20
14
  'value' => value_as_json,
21
15
  }
22
- as_json['name'] = gate.name.to_s unless exclude_name
16
+ as_json['name'] = @gate.name.to_s unless exclude_name
23
17
  as_json
24
18
  end
25
19
 
@@ -30,7 +24,7 @@ module Flipper
30
24
 
31
25
  # json doesn't like sets
32
26
  def value_as_json
33
- JSON_ARRAY_TYPES.include?(data_type) ? value.to_a : value
27
+ JSON_ARRAY_TYPES.include?(@gate.data_type) ? @value.to_a : @value
34
28
  end
35
29
  end
36
30
  end
data/lib/flipper/api.rb CHANGED
@@ -9,11 +9,15 @@ module Flipper
9
9
 
10
10
  def self.app(flipper = nil, options = {})
11
11
  env_key = options.fetch(:env_key, 'flipper')
12
+ use_rewindable_middleware = options.fetch(:use_rewindable_middleware) {
13
+ Gem::Version.new(Rack.release) >= Gem::Version.new('3.0.0')
14
+ }
12
15
  app = ->(_) { [404, { Rack::CONTENT_TYPE => CONTENT_TYPE }, ['{}'.freeze]] }
13
16
  builder = Rack::Builder.new
14
17
  yield builder if block_given?
15
18
  builder.use Rack::Head
16
19
  builder.use Rack::Deflater
20
+ builder.use Rack::RewindableInput::Middleware if use_rewindable_middleware
17
21
  builder.use Flipper::Api::JsonParams
18
22
  builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key
19
23
  builder.use Flipper::Api::Middleware, env_key: env_key
@@ -1,5 +1,5 @@
1
1
  module Flipper
2
- VERSION = '1.2.2'.freeze
2
+ VERSION = '1.3.0.pre'.freeze
3
3
 
4
4
  REQUIRED_RUBY_VERSION = '2.6'.freeze
5
5
  NEXT_REQUIRED_RUBY_VERSION = '3.0'.freeze
@@ -8,6 +8,9 @@ RSpec.describe Flipper::Api do
8
8
 
9
9
  get '/features'
10
10
 
11
+ expect(last_request.env["flipper.action_class"]).to eq(Flipper::Api::V1::Actions::Features)
12
+ expect(last_request.env["flipper.action_method"]).to eq("get")
13
+
11
14
  expect(last_response.status).to be(200)
12
15
  feature_names = json_response.fetch('features').map { |feature| feature.fetch('key') }
13
16
  expect(feature_names).to eq(%w(a b))
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: 1.2.2
4
+ version: 1.3.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-19 00:00:00.000000000 Z
11
+ date: 2024-03-14 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: 1.2.2
39
+ version: 1.3.0.pre
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: 1.2.2
46
+ version: 1.3.0.pre
47
47
  description:
48
48
  email: support@flippercloud.io
49
49
  executables: []
@@ -97,7 +97,7 @@ metadata:
97
97
  homepage_uri: https://www.flippercloud.io
98
98
  source_code_uri: https://github.com/flippercloud/flipper
99
99
  bug_tracker_uri: https://github.com/flippercloud/flipper/issues
100
- changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.2.2
100
+ changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.3.0.pre
101
101
  post_install_message:
102
102
  rdoc_options: []
103
103
  require_paths: