flipper-api 0.9.0.beta1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/flipper/api/action.rb +16 -1
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/api/action_spec.rb +59 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 190b68fb4dca2dbed9035080387164ddf37f803a
|
4
|
+
data.tar.gz: 987efcf4cfa1434b3d02110e80985a23cc6f2aff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0b8d6d33fa9590e32f1cb44f70c485957b23fb11bf614c3882d3c509f5a39d9b81a8ea331b85811b9003f32130e5c6c05f04a3210a514e0d9312248c7dffe26
|
7
|
+
data.tar.gz: 61433fe1086f7a69779a36effc45ec36dad24b1fbca77789991917675f35da4af91dfc056ef37fe9afc39a25b84aff165572b5c1d02365fa3e835cfb043f5f67
|
data/lib/flipper/api/action.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'flipper/api/error'
|
3
|
+
require 'json'
|
4
|
+
|
1
5
|
module Flipper
|
2
6
|
module Api
|
3
7
|
class Action
|
4
8
|
extend Forwardable
|
5
9
|
|
10
|
+
VALID_REQUEST_METHOD_NAMES = Set.new([
|
11
|
+
"get".freeze,
|
12
|
+
"post".freeze,
|
13
|
+
"put".freeze,
|
14
|
+
"delete".freeze,
|
15
|
+
]).freeze
|
16
|
+
|
6
17
|
# Public: Call this in subclasses so the action knows its route.
|
7
18
|
#
|
8
19
|
# regex - The Regexp that this action should run for.
|
@@ -47,7 +58,7 @@ module Flipper
|
|
47
58
|
#
|
48
59
|
# Returns whatever the request method returns in the action.
|
49
60
|
def run
|
50
|
-
if respond_to?(request_method_name)
|
61
|
+
if valid_request_method? && respond_to?(request_method_name)
|
51
62
|
catch(:halt) { send(request_method_name) }
|
52
63
|
else
|
53
64
|
raise Api::RequestMethodNotSupported, "#{self.class} does not support request method #{request_method_name.inspect}"
|
@@ -111,6 +122,10 @@ module Flipper
|
|
111
122
|
def path_parts
|
112
123
|
@request.path.split("/")
|
113
124
|
end
|
125
|
+
|
126
|
+
def valid_request_method?
|
127
|
+
VALID_REQUEST_METHOD_NAMES.include?(request_method_name)
|
128
|
+
end
|
114
129
|
end
|
115
130
|
end
|
116
131
|
end
|
data/lib/flipper/version.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
RSpec.describe Flipper::Api::Action do
|
4
|
+
let(:action_subclass) {
|
5
|
+
Class.new(described_class) do
|
6
|
+
def noooope
|
7
|
+
raise "should never run this"
|
8
|
+
end
|
9
|
+
|
10
|
+
def get
|
11
|
+
[200, {}, "get"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def post
|
15
|
+
[200, {}, "post"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def put
|
19
|
+
[200, {}, "put"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete
|
23
|
+
[200, {}, "delete"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
}
|
27
|
+
|
28
|
+
it "won't run method that isn't whitelisted" do
|
29
|
+
fake_request = Struct.new(:request_method, :env, :session).new("NOOOOPE", {}, {})
|
30
|
+
action = action_subclass.new(flipper, fake_request)
|
31
|
+
expect {
|
32
|
+
action.run
|
33
|
+
}.to raise_error(Flipper::Api::RequestMethodNotSupported)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "will run get" do
|
37
|
+
fake_request = Struct.new(:request_method, :env, :session).new("GET", {}, {})
|
38
|
+
action = action_subclass.new(flipper, fake_request)
|
39
|
+
expect(action.run).to eq([200, {}, "get"])
|
40
|
+
end
|
41
|
+
|
42
|
+
it "will run post" do
|
43
|
+
fake_request = Struct.new(:request_method, :env, :session).new("POST", {}, {})
|
44
|
+
action = action_subclass.new(flipper, fake_request)
|
45
|
+
expect(action.run).to eq([200, {}, "post"])
|
46
|
+
end
|
47
|
+
|
48
|
+
it "will run put" do
|
49
|
+
fake_request = Struct.new(:request_method, :env, :session).new("PUT", {}, {})
|
50
|
+
action = action_subclass.new(flipper, fake_request)
|
51
|
+
expect(action.run).to eq([200, {}, "put"])
|
52
|
+
end
|
53
|
+
|
54
|
+
it "will run delete" do
|
55
|
+
fake_request = Struct.new(:request_method, :env, :session).new("DELETE", {}, {})
|
56
|
+
action = action_subclass.new(flipper, fake_request)
|
57
|
+
expect(action.run).to eq([200, {}, "delete"])
|
58
|
+
end
|
59
|
+
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.9.0
|
4
|
+
version: 0.9.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: 2016-
|
11
|
+
date: 2016-07-05 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.9.0
|
39
|
+
version: 0.9.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.9.0
|
46
|
+
version: 0.9.0
|
47
47
|
description: Rack middleware that provides an API for the flipper gem.
|
48
48
|
email:
|
49
49
|
- nunemaker@gmail.com
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/flipper/api/v1/decorators/feature.rb
|
64
64
|
- lib/flipper/api/v1/decorators/gate.rb
|
65
65
|
- lib/flipper/version.rb
|
66
|
+
- spec/flipper/api/action_spec.rb
|
66
67
|
- spec/flipper/api/v1/actions/boolean_gate_spec.rb
|
67
68
|
- spec/flipper/api/v1/actions/feature_spec.rb
|
68
69
|
homepage: https://github.com/jnunemaker/flipper
|
@@ -80,9 +81,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
81
|
version: '0'
|
81
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
83
|
requirements:
|
83
|
-
- - "
|
84
|
+
- - ">="
|
84
85
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
86
|
+
version: '0'
|
86
87
|
requirements: []
|
87
88
|
rubyforge_project:
|
88
89
|
rubygems_version: 2.4.5.1
|
@@ -90,5 +91,6 @@ signing_key:
|
|
90
91
|
specification_version: 4
|
91
92
|
summary: API for the Flipper gem
|
92
93
|
test_files:
|
94
|
+
- spec/flipper/api/action_spec.rb
|
93
95
|
- spec/flipper/api/v1/actions/boolean_gate_spec.rb
|
94
96
|
- spec/flipper/api/v1/actions/feature_spec.rb
|