sliver 0.1.0 → 0.2.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/README.md +1 -1
- data/lib/sliver.rb +1 -0
- data/lib/sliver/action.rb +4 -0
- data/lib/sliver/hook.rb +9 -0
- data/lib/sliver/runner.rb +35 -6
- data/sliver.gemspec +1 -1
- data/spec/acceptance/class_api_spec.rb +31 -11
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4cafe27f4c73054d56b959d387c2ad112317a91
|
4
|
+
data.tar.gz: 7ef015ae4473548c4191b4d6bea1d7e5813a4f31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a58eb401484aa99d444765a5b1cf6c66d1b8fbd6bcafeff5dd16ff0b54b26018369467df73096bedccb2cc728e0b22aa5552e4f1a34b7b8962664b6f0debd1a
|
7
|
+
data.tar.gz: 9ff0a07cf83cd4e73dcac29a6706d7e9b4881aca903f3ff46ca463cb35136c031ad16f47b9f27f785bae3687d19eb6806a150e381539d3059fd4d2917c1467d5
|
data/README.md
CHANGED
data/lib/sliver.rb
CHANGED
data/lib/sliver/action.rb
CHANGED
data/lib/sliver/hook.rb
ADDED
data/lib/sliver/runner.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
class Sliver::Runner
|
2
2
|
def initialize(klass, environment)
|
3
3
|
@klass, @environment = klass, environment
|
4
|
+
|
5
|
+
@guarded = false
|
4
6
|
end
|
5
7
|
|
6
8
|
def call
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
action.call unless action.skip?
|
9
|
+
pass_guards
|
10
|
+
action.call unless skip_action?
|
11
|
+
post_process
|
13
12
|
|
14
13
|
response.to_a
|
15
14
|
end
|
@@ -26,7 +25,37 @@ class Sliver::Runner
|
|
26
25
|
klass.guards
|
27
26
|
end
|
28
27
|
|
28
|
+
def guarded?
|
29
|
+
@guarded
|
30
|
+
end
|
31
|
+
|
32
|
+
def guarded!
|
33
|
+
@guarded = true
|
34
|
+
end
|
35
|
+
|
36
|
+
def pass_guards
|
37
|
+
guard_classes.each do |guard_class|
|
38
|
+
guard = guard_class.new action, response
|
39
|
+
next if guard.continue?
|
40
|
+
|
41
|
+
guard.respond
|
42
|
+
guarded!
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def post_process
|
47
|
+
processors.each { |processor| processor.call }
|
48
|
+
end
|
49
|
+
|
50
|
+
def processors
|
51
|
+
klass.processors.collect { |klass| klass.new action, response }
|
52
|
+
end
|
53
|
+
|
29
54
|
def response
|
30
55
|
@response ||= Sliver::Response.new
|
31
56
|
end
|
57
|
+
|
58
|
+
def skip_action?
|
59
|
+
guarded? || action.skip?
|
60
|
+
end
|
32
61
|
end
|
data/sliver.gemspec
CHANGED
@@ -42,22 +42,15 @@ class SkippedAction
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
class MyParamGuard
|
46
|
-
def initialize(action)
|
47
|
-
@action = action
|
48
|
-
end
|
49
|
-
|
45
|
+
class MyParamGuard < Sliver::Hook
|
50
46
|
def continue?
|
51
47
|
action.request.params['hello'] == 'world'
|
52
48
|
end
|
53
49
|
|
54
|
-
def
|
55
|
-
|
50
|
+
def respond
|
51
|
+
response.status = 404
|
52
|
+
response.body = ['Not Found']
|
56
53
|
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
attr_reader :action
|
61
54
|
end
|
62
55
|
|
63
56
|
class GuardedAction
|
@@ -97,6 +90,25 @@ class MultiPathPartAction
|
|
97
90
|
end
|
98
91
|
end
|
99
92
|
|
93
|
+
class JsonProcessor < Sliver::Hook
|
94
|
+
def call
|
95
|
+
response.headers['Content-Type'] = 'application/json'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class ProcessedAction
|
100
|
+
include Sliver::Action
|
101
|
+
|
102
|
+
def self.processors
|
103
|
+
[JsonProcessor]
|
104
|
+
end
|
105
|
+
|
106
|
+
def call
|
107
|
+
response.status = 200
|
108
|
+
response.body = ['[]']
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
100
112
|
describe 'Class-based Sliver API' do
|
101
113
|
include Rack::Test::Methods
|
102
114
|
|
@@ -109,6 +121,7 @@ describe 'Class-based Sliver API' do
|
|
109
121
|
api.connect :get, '/unguard', UnguardedAction
|
110
122
|
api.connect :get, '/my/:id', IdAction
|
111
123
|
api.connect :get, '/my/:first/:second', MultiPathPartAction
|
124
|
+
api.connect :get, '/processed', ProcessedAction
|
112
125
|
end }
|
113
126
|
|
114
127
|
it 'constructs responses' do
|
@@ -172,4 +185,11 @@ describe 'Class-based Sliver API' do
|
|
172
185
|
expect(last_response.status).to eq(200)
|
173
186
|
expect(last_response.body).to eq('10:foo')
|
174
187
|
end
|
188
|
+
|
189
|
+
it 'handles processors' do
|
190
|
+
get '/processed'
|
191
|
+
|
192
|
+
expect(last_response.status).to eq(200)
|
193
|
+
expect(last_response.headers['Content-Type']).to eq('application/json')
|
194
|
+
end
|
175
195
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sliver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/sliver/action.rb
|
70
70
|
- lib/sliver/api.rb
|
71
71
|
- lib/sliver/endpoints.rb
|
72
|
+
- lib/sliver/hook.rb
|
72
73
|
- lib/sliver/path.rb
|
73
74
|
- lib/sliver/response.rb
|
74
75
|
- lib/sliver/runner.rb
|