lookout-rack-utils 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +4 -0
- data/lib/lookout/rack/utils/subroute.rb +17 -3
- data/lib/lookout/rack/utils/version.rb +1 -1
- data/spec/subroute_spec.rb +41 -0
- metadata +166 -141
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzIxNjcxNGNjYjY5YWRjNTZjMTZiYWM5YTZlZGQ5MTI4NDQ5OGJiNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZWJjMzVjYWFmZTk3YzYxOTcwMTc4MzZhMzRjNGU3MTI5MGI0YjEyNg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjIzYjIyNjdkMTkzZWZmYWM0MDlmMjNiMGUyNjkyOTFlYjQxMWI2ZjA3ZjMz
|
10
|
+
ZTUwODFkNmIxMzNhMjRhN2VmZmVmNWM5NjA1ZGMyZDQwODBmNGY4YmU1MjRh
|
11
|
+
MDk3ZWJjYTAwNmE3Y2JmZTI5YWU0MmM0MWIzNDYzNzAzZGE2ZWU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjAzMGU4YjdkNmE2M2U2YmZlZTk4ZDEyMTAzM2I3Y2Q0ZmRjZTJmYTE1NmNm
|
14
|
+
MjQ5YjcxYTkzMjRkNzEyZjllODJkZmU2MTJhODY4ODNkYjk5YTE4YjE5Zjll
|
15
|
+
MWM3OTM0NWUzZTMwODc1NDVmMDI5MjY2OTFkYzMxMzk0ODlmOWU=
|
data/README.md
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
module Lookout::Rack::Utils
|
2
2
|
module Subroute
|
3
|
+
HTTP_METHODS = %w(DELETE GET HEAD OPTIONS LINK PATCH POST PUT TRACE UNLINK).freeze
|
4
|
+
|
3
5
|
def subroute!(relative_path, options={})
|
4
|
-
|
6
|
+
# Create a copy of our App instance to preserve the state of the
|
7
|
+
# caller's env hash
|
8
|
+
subserver = dup
|
9
|
+
request_opts = {'PATH_INFO' => relative_path}
|
10
|
+
|
11
|
+
request_opts['REQUEST_METHOD'] = options.delete(:request_method).upcase if options[:request_method]
|
12
|
+
http_verb = request_opts['REQUEST_METHOD'] || subserver.request.request_method
|
13
|
+
|
14
|
+
raise ArgumentError, "Invalid http method: #{http_verb}" unless HTTP_METHODS.include?(http_verb)
|
15
|
+
|
5
16
|
# modify rack environment using Rack::Request- store passed in key/value
|
6
17
|
# pairs into hash associated with the parameters of the current http verb
|
7
|
-
options.each { |k,v| request.send(http_verb)[k] = v }
|
8
|
-
|
18
|
+
options.each { |k,v| subserver.request.send(http_verb)[k] = v }
|
19
|
+
# Invoking Sinatra::Base#call! on our duplicated app instance. Sinatra's
|
20
|
+
# call will dup the app instance and then call!, so skip Sinatra's dup
|
21
|
+
# since we've done that here.
|
22
|
+
subcode, subheaders, body = subserver.call!(env.merge(request_opts))
|
9
23
|
return [subcode, body.first]
|
10
24
|
end
|
11
25
|
|
data/spec/subroute_spec.rb
CHANGED
@@ -17,6 +17,20 @@ describe Lookout::Rack::Utils::Subroute, :type => :route do
|
|
17
17
|
get '/subrouted/:id' do |id|
|
18
18
|
subroute!('/test_route', :id => id)
|
19
19
|
end
|
20
|
+
|
21
|
+
delete '/test_delete' do
|
22
|
+
status 201
|
23
|
+
{ :deleted => true }.to_json
|
24
|
+
end
|
25
|
+
|
26
|
+
get '/test_delete' do
|
27
|
+
subroute!('/test_delete', :request_method => 'DELETE')
|
28
|
+
end
|
29
|
+
|
30
|
+
get '/multiroute' do
|
31
|
+
subroute!('/test_delete', :request_method => 'DELETE')
|
32
|
+
subroute!('/test_route', :id => 1)
|
33
|
+
end
|
20
34
|
end
|
21
35
|
end
|
22
36
|
|
@@ -36,6 +50,33 @@ describe Lookout::Rack::Utils::Subroute, :type => :route do
|
|
36
50
|
expect([subrouted.status, subrouted.body]).to eql [200, body]
|
37
51
|
end
|
38
52
|
end
|
53
|
+
|
54
|
+
context 'changing the http verb' do
|
55
|
+
context 'to a valid verb' do
|
56
|
+
subject(:subrouted) { get "/test_delete" }
|
57
|
+
|
58
|
+
its(:status) { should be 201 }
|
59
|
+
|
60
|
+
it 'should return expected output' do
|
61
|
+
expect(JSON.parse(subrouted.body)['deleted']).to be_true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'to an invalid verb' do
|
66
|
+
subject(:subrouted) { subroute!('/test_delete_invalid', :request_path => 'DELATE') }
|
67
|
+
|
68
|
+
it 'should throw an error' do
|
69
|
+
expect { subrouted }.to raise_error
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with multiple subroutes' do
|
74
|
+
subject(:subrouted) { get '/multiroute' }
|
75
|
+
it 'should return the status and body of the second subroute' do
|
76
|
+
expect([subrouted.status, subrouted.body]).to eql [200, { :id => 1 }.to_json]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
39
80
|
end
|
40
81
|
|
41
82
|
describe '#succeeded?' do
|
metadata
CHANGED
@@ -1,170 +1,204 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: lookout-rack-utils
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.5.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.6.0
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Ian Smith
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
16
14
|
name: bundler
|
17
|
-
requirement:
|
18
|
-
|
19
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
20
17
|
- - ~>
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version:
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
23
20
|
type: :development
|
24
21
|
prerelease: false
|
25
|
-
version_requirements:
|
26
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
27
28
|
name: rake
|
28
|
-
requirement:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
version: "0"
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements:
|
37
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
38
42
|
name: rspec
|
39
|
-
requirement:
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
version: "0"
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
45
48
|
type: :development
|
46
49
|
prerelease: false
|
47
|
-
version_requirements:
|
48
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
49
56
|
name: rack-test
|
50
|
-
requirement:
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
version: "0"
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
56
62
|
type: :development
|
57
63
|
prerelease: false
|
58
|
-
version_requirements:
|
59
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
60
70
|
name: sinatra
|
61
|
-
requirement:
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
version: "0"
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
67
76
|
type: :development
|
68
77
|
prerelease: false
|
69
|
-
version_requirements:
|
70
|
-
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
71
84
|
name: timecop
|
72
|
-
requirement:
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
version: "0"
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
78
90
|
type: :development
|
79
91
|
prerelease: false
|
80
|
-
version_requirements:
|
81
|
-
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
82
98
|
name: i18n
|
83
|
-
requirement:
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
version: "0"
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
89
104
|
type: :runtime
|
90
105
|
prerelease: false
|
91
|
-
version_requirements:
|
92
|
-
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
93
112
|
name: rack
|
94
|
-
requirement:
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
version: "0"
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
100
118
|
type: :runtime
|
101
119
|
prerelease: false
|
102
|
-
version_requirements:
|
103
|
-
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
104
126
|
name: rack-graphite
|
105
|
-
requirement:
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
version: "0"
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
111
132
|
type: :runtime
|
112
133
|
prerelease: false
|
113
|
-
version_requirements:
|
114
|
-
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
115
140
|
name: rack-requestash
|
116
|
-
requirement:
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
version: "0"
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
122
146
|
type: :runtime
|
123
147
|
prerelease: false
|
124
|
-
version_requirements:
|
125
|
-
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
126
154
|
name: configatron
|
127
|
-
requirement:
|
128
|
-
|
129
|
-
requirements:
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
130
157
|
- - ~>
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
version:
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '2.13'
|
133
160
|
type: :runtime
|
134
161
|
prerelease: false
|
135
|
-
version_requirements:
|
136
|
-
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '2.13'
|
167
|
+
- !ruby/object:Gem::Dependency
|
137
168
|
name: log4r
|
138
|
-
requirement:
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
version: "0"
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
144
174
|
type: :runtime
|
145
175
|
prerelease: false
|
146
|
-
version_requirements:
|
147
|
-
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
148
182
|
name: lookout-statsd
|
149
|
-
requirement:
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
- !ruby/object:Gem::Version
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
154
187
|
version: 0.7.0
|
155
188
|
type: :runtime
|
156
189
|
prerelease: false
|
157
|
-
version_requirements:
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ! '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 0.7.0
|
158
195
|
description: A collection of rack utils.
|
159
|
-
email:
|
196
|
+
email:
|
160
197
|
- ian.smith@lookout.com
|
161
198
|
executables: []
|
162
|
-
|
163
199
|
extensions: []
|
164
|
-
|
165
200
|
extra_rdoc_files: []
|
166
|
-
|
167
|
-
files:
|
201
|
+
files:
|
168
202
|
- .gitignore
|
169
203
|
- Gemfile
|
170
204
|
- LICENSE.txt
|
@@ -185,40 +219,31 @@ files:
|
|
185
219
|
- spec/subroute_spec.rb
|
186
220
|
- spec/support/routehelpers.rb
|
187
221
|
- spec/support/subroutehelpers.rb
|
188
|
-
homepage:
|
189
|
-
licenses:
|
222
|
+
homepage: ''
|
223
|
+
licenses:
|
190
224
|
- MIT
|
225
|
+
metadata: {}
|
191
226
|
post_install_message:
|
192
227
|
rdoc_options: []
|
193
|
-
|
194
|
-
require_paths:
|
228
|
+
require_paths:
|
195
229
|
- lib
|
196
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
none: false
|
207
|
-
requirements:
|
208
|
-
- - ">="
|
209
|
-
- !ruby/object:Gem::Version
|
210
|
-
hash: 3856689036968627434
|
211
|
-
segments:
|
212
|
-
- 0
|
213
|
-
version: "0"
|
230
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
231
|
+
requirements:
|
232
|
+
- - ! '>='
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '0'
|
235
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
|
+
requirements:
|
237
|
+
- - ! '>='
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: '0'
|
214
240
|
requirements: []
|
215
|
-
|
216
241
|
rubyforge_project:
|
217
|
-
rubygems_version:
|
242
|
+
rubygems_version: 2.2.2
|
218
243
|
signing_key:
|
219
|
-
specification_version:
|
220
|
-
summary:
|
221
|
-
test_files:
|
244
|
+
specification_version: 4
|
245
|
+
summary: ''
|
246
|
+
test_files:
|
222
247
|
- spec/graphite_spec.rb
|
223
248
|
- spec/i18n_spec.rb
|
224
249
|
- spec/log_spec.rb
|